diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46db709c3fef..cb7dd4ff3909 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,7 +67,6 @@ repos: - id: fix-byte-order-marker - id: forbid-submodules - id: mixed-line-ending - exclude: \.cs$ - id: trailing-whitespace files: \.(bat|cfg|cs|css|gitignore|header|in|install|java|md|properties|py|rb|rc|sh|sql|te|template|txt|ucls|vue|xml|xsl|yaml|yml)$|^cloud-cli/bindir/cloud-tool$|^debian/changelog$ args: [--markdown-linebreak-ext=md] diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceController1Test.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceController1Test.cs index 6d8e2b2e15a6..6f9e68302f82 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceController1Test.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceController1Test.cs @@ -1,350 +1,350 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -using System; -using CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2; -using System.Management; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; -using System.IO; -using log4net; -using HypervResource; -using CloudStack.Plugin.AgentShell; -using System.Collections.Generic; -using NSubstitute; -using System.Web.Http; -using Xunit; - -namespace ServerResource.Tests -{ - public class HypervResourceController1Test - { - protected static string testCifsUrl = AgentSettings.Default.testCifsUrl; - protected static string testCifsPath = AgentSettings.Default.testCifsPath; - protected static String testPrimaryDataStoreHost = HypervResourceController.config.StorageIpAddress; - protected static String testS3TemplateName = AgentSettings.Default.testS3TemplateName; - protected static String testCifsTemplateName = AgentSettings.Default.testS3TemplateName; - protected static String testSystemVMTemplateName = AgentSettings.Default.testSystemVMTemplateName; - protected static String testSystemVMTemplateNameNoExt = AgentSettings.Default.testSystemVMTemplateNameNoExt; - protected static String testLocalStoreUUID = "5fe2bad3-d785-394e-9949-89786b8a63d2"; - protected static String testLocalStorePath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "storagepool"); - protected static String testSecondaryStoreLocalPath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "secondary"); - - // TODO: differentiate between NFS and HTTP template URLs. - protected static String testSampleTemplateUUID = "TestCopiedLocalTemplate.vhdx"; - protected static String testSampleTemplateURL = testSampleTemplateUUID; - - // test volumes are both a minimal size vhdx. Changing the extension to .vhd makes on corrupt. - protected static String testSampleVolumeWorkingUUID = "TestVolumeLegit.vhdx"; - protected static String testSampleVolumeCorruptUUID = "TestVolumeCorrupt.vhd"; - protected static String testSampleVolumeTempUUID = "TestVolumeTemp.vhdx"; - protected static String testSampleVolumeTempUUIDNoExt = "TestVolumeTemp"; - protected static String testSampleVolumeWorkingURIJSON; - protected static String testSampleVolumeCorruptURIJSON; - protected static String testSampleVolumeTempURIJSON; - - protected static String testSampleTemplateURLJSON; - protected static String testLocalStorePathJSON; - - protected static IWmiCallsV2 wmiCallsV2; - - - private static ILog s_logger = LogManager.GetLogger(typeof(HypervResourceController1Test)); - - /// - /// Test WmiCalls to which incoming HTTP POST requests are dispatched. - /// - /// TODO: revise beyond first approximation - /// First approximation is a quick port of the existing Java tests for Hyper-V server resource. - /// A second approximation would use the AgentShell settings files directly. - /// A third approximation would look to invoke ServerResource methods via an HTTP request - /// - - public HypervResourceController1Test() - { - wmiCallsV2 = Substitute.For(); - //AgentService.ConfigServerResource(); - HypervResourceController.config.PrivateMacAddress = AgentSettings.Default.private_mac_address; - HypervResourceController.config.PrivateNetmask = AgentSettings.Default.private_ip_netmask; - HypervResourceController.config.StorageIpAddress = HypervResourceController.config.PrivateIpAddress; - HypervResourceController.config.StorageMacAddress = HypervResourceController.config.PrivateMacAddress; - HypervResourceController.config.StorageNetmask = HypervResourceController.config.PrivateNetmask; - - - // Used to create existing StoragePool in preparation for the ModifyStoragePool - testLocalStoreUUID = AgentSettings.Default.local_storage_uuid.ToString(); - - // Make sure secondary store is available. - string fullPath = Path.GetFullPath(testSecondaryStoreLocalPath); - s_logger.Info("Test secondary storage in " + fullPath); - DirectoryInfo testSecondarStoreDir = new DirectoryInfo(fullPath); - if (!testSecondarStoreDir.Exists) - { - try - { - testSecondarStoreDir.Create(); - } - catch (System.IO.IOException ex) - { - throw new NotImplementedException("Need to be able to create the folder " + testSecondarStoreDir.FullName + " failed due to " + ex.Message); - } - } - - // Convert to secondary storage string to canonical path - testSecondaryStoreLocalPath = testSecondarStoreDir.FullName; - AgentSettings.Default.local_secondary_storage_path = testSecondaryStoreLocalPath; - - // Make sure local primary storage is available - DirectoryInfo testPoolDir = new DirectoryInfo(testLocalStorePath); - //Assert.True(testPoolDir.Exists, "To simulate local file system Storage Pool, you need folder at " + testPoolDir.FullName); - - // Convert to local primary storage string to canonical path - testLocalStorePath = testPoolDir.FullName; - AgentSettings.Default.local_storage_path = testLocalStorePath; - - // Clean up old test files in local storage folder - FileInfo testVolWorks = new FileInfo(Path.Combine(testLocalStorePath, testSampleVolumeWorkingUUID)); - // Assert.True(testVolWorks.Exists, "Create a working virtual disk at " + testVolWorks.FullName); - - testSampleTemplateURLJSON = JsonConvert.SerializeObject(testSampleTemplateUUID); - s_logger.Info("Created " + testSampleTemplateURLJSON + " in local storage."); - - - // Capture other JSON encoded paths - testSampleVolumeWorkingURIJSON = Newtonsoft.Json.JsonConvert.SerializeObject(testVolWorks.FullName); - testLocalStorePathJSON = JsonConvert.SerializeObject(testLocalStorePath); - - // TODO: may need to initialise the server resource in future. - // s_hypervresource.initialize(); - - // Verify sample template is in place storage pool - s_logger.Info("setUp complete, sample StoragePool at " + testLocalStorePathJSON - + " sample template at " + testSampleTemplateURLJSON); - } - - private String CreateTestDiskImageFromExistingImage(FileInfo srcFile, - String dstPath, - String dstFileName) - { - var newFullname = Path.Combine(dstPath, dstFileName); - var newFileInfo = new FileInfo(newFullname); - if (!newFileInfo.Exists) - { - newFileInfo = srcFile.CopyTo(newFullname); - } - newFileInfo.Refresh(); - Assert.True(newFileInfo.Exists, "Attempted to create " + newFullname + " from " + newFileInfo.FullName); - - return JsonConvert.SerializeObject(newFileInfo.FullName); - } - - [Fact] - public void TestCreateCommand() - { - DirectoryInfo localStorePath = new DirectoryInfo(testLocalStorePath); - if (!localStorePath.Exists) - { - try - { - localStorePath.Create(); - } - catch (System.IO.IOException ex) - { - throw new NotImplementedException("Need to be able to create the folder " + localStorePath.FullName + " failed due to " + ex.Message); - } - } - - FileInfo sampleTemplateFile = new FileInfo(Path.Combine(testLocalStorePath, testSampleTemplateUUID)); - if (!sampleTemplateFile.Exists) - { - //Create a file to write to. - using (StreamWriter sw = sampleTemplateFile.CreateText()) - { - sw.WriteLine("This is fake template file for test"); - } - } - var counter = 0; - wmiCallsV2.When(x => x.CreateDynamicVirtualHardDisk(Arg.Any(), Arg.Any())).Do(x => counter++); - // TODO: Need sample to update the test. - // Arrange - String createCmd = "{\"volId\":10,\"pool\":{\"id\":201,\"uuid\":\"" + testLocalStoreUUID + "\",\"host\":\"" + HypervResourceController.config.StorageIpAddress + "\"" + - ",\"path\":" + testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"},\"diskCharacteristics\":{\"size\":0," + - "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-9\",\"useLocalStorage\":true,\"recreatable\":true,\"diskOfferingId\":11," + - "\"volumeId\":10,\"hyperType\":\"Hyperv\"},\"templateUrl\":" + testSampleTemplateURLJSON + ",\"contextMap\":{},\"wait\":0}"; - dynamic jsonCreateCmd = JsonConvert.DeserializeObject(createCmd); - HypervResourceController rsrcServer = new HypervResourceController(); - HypervResourceController.wmiCallsV2 = wmiCallsV2; - - Assert.True(Directory.Exists(testLocalStorePath), testLocalStorePath + " does not exist "); - string filePath = Path.Combine(testLocalStorePath, (string)JsonConvert.DeserializeObject(testSampleTemplateURLJSON)); - Assert.True(File.Exists(filePath), "The template we make volumes from is missing from path " + filePath); - int fileCount = Directory.GetFiles(testLocalStorePath).Length; - s_logger.Debug(" test local store has " + fileCount + "files"); - - // Act - // Test requires there to be a template at the tempalteUrl, which is its location in the local file system. - dynamic jsonResult = rsrcServer.CreateCommand(jsonCreateCmd); - s_logger.Debug("CreateDynamicVirtualHardDisk method is called " + counter + " times"); - - //Assert.Equal(counter, 1); - - JObject ansAsProperty2 = jsonResult[0]; - dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.CreateAnswer); - Assert.NotNull(ans); - Assert.True((bool)ans.result, "Failed to CreateCommand due to " + (string)ans.result); - Assert.Equal(Directory.GetFiles(testLocalStorePath).Length, fileCount + 1); - FileInfo newFile = new FileInfo((string)ans.volume.path); - Assert.True(newFile.Length > 0, "The new file should have a size greater than zero"); - newFile.Delete(); - sampleTemplateFile.Delete(); - } - - [Fact] - public void TestDestroyCommand() - { - testSampleVolumeTempURIJSON = "\"storagepool\""; - // Arrange - String destroyCmd = //"{\"volume\":" + getSampleVolumeObjectTO() + "}"; - "{\"volume\":{\"name\":\"" + testSampleVolumeTempUUIDNoExt - + "\",\"storagePoolType\":\"Filesystem\"," - + "\"mountPoint\":" - + testLocalStorePathJSON - + ",\"path\":" + testSampleVolumeTempURIJSON - + ",\"storagePoolUuid\":\"" + testLocalStoreUUID - + "\"," - + "\"type\":\"ROOT\",\"id\":9,\"size\":0}}"; - - ImageManagementService imgmgr = new ImageManagementService(); - wmiCallsV2.GetImageManagementService().Returns(imgmgr); - - HypervResourceController rsrcServer = new HypervResourceController(); - HypervResourceController.wmiCallsV2 = wmiCallsV2; - - dynamic jsonDestroyCmd = JsonConvert.DeserializeObject(destroyCmd); - - // Act - dynamic destroyAns = rsrcServer.DestroyCommand(jsonDestroyCmd); - - // Assert - JObject ansAsProperty2 = destroyAns[0]; - dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.Answer); - String path = jsonDestroyCmd.volume.path; - Assert.True((bool)ans.result, "DestroyCommand did not succeed " + ans.details); - Assert.True(!File.Exists(path), "Failed to delete file " + path); - } - - [Fact] - public void TestStartCommand() - { - ComputerSystem system = new ComputerSystem(); - wmiCallsV2.DeployVirtualMachine(Arg.Any(), Arg.Any()).Returns(system); - - // Arrange - HypervResourceController rsrcServer = new HypervResourceController(); - HypervResourceController.wmiCallsV2 = wmiCallsV2; - String sample = getSampleStartCommand(); - - - dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample); - - // Act - dynamic startAns = rsrcServer.StartCommand(jsonStartCmd); - - // Assert - Assert.NotNull(startAns[0][CloudStackTypes.StartAnswer]); - Assert.True((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details); - - Assert.Null((string)startAns[0][CloudStackTypes.StartAnswer].details); - } - - [Fact] - public void TestStopCommand() - { - //string vmName = "Test VM"; - var counter = 0; - wmiCallsV2.When(x => x.DestroyVm(Arg.Any())).Do(x => counter++); - - // Arrange - HypervResourceController rsrcServer = new HypervResourceController(); - HypervResourceController.wmiCallsV2 = wmiCallsV2; - - String sampleStop = "{\"isProxy\":false,\"vmName\":\"i-2-17-VM\",\"contextMap\":{},\"checkBeforeCleanup\":false,\"wait\":0}"; - dynamic jsonStopCmd = JsonConvert.DeserializeObject(sampleStop); - - // Act - dynamic stopAns = rsrcServer.StopCommand(jsonStopCmd); - - // Assert VM is gone! - Assert.NotNull(stopAns[0][CloudStackTypes.StopAnswer]); - Assert.True((bool)stopAns[0][CloudStackTypes.StopAnswer].result, "StopCommand did not succeed " + stopAns[0][CloudStackTypes.StopAnswer].details); - - Assert.Null((string)stopAns[0][CloudStackTypes.StopAnswer].details); - Assert.Equal(counter, 1); - } - - public static String getSamplePrimaryDataStoreInfo() - { - String samplePrimaryDataStoreInfo = - "{\"org.apache.cloudstack.storage.to.PrimaryDataStoreTO\":" + - "{\"uuid\":\"" + testLocalStoreUUID + "\"," + - "\"id\":201," + - "\"host\":\"" + testPrimaryDataStoreHost + "\"," + - "\"type\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO - "\"poolType\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO - "\"path\":" + testLocalStorePathJSON + "," + - "\"port\":0}" + - "}"; - return samplePrimaryDataStoreInfo; - } - - public static String getSampleVolumeObjectTO() - { - String sampleVolumeObjectTO = - "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + - "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + - "\"volumeType\":\"ROOT\"," + - "\"format\":\"VHDX\"," + - "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + - "\"name\":\"" + testSampleVolumeTempUUIDNoExt + "\"," + - "\"size\":52428800," + - "\"volumeId\":10," + - // "\"vmName\":\"i-3-5-VM\"," + // TODO: do we have to fill in the vmName? - "\"accountId\":3,\"id\":10}" + - "}"; // end of destTO - return sampleVolumeObjectTO; - } - - public static String getSampleStartCommand() - { - String sample = "{\"vm\":{\"id\":17,\"name\":\"i-2-17-VM\",\"type\":\"User\",\"cpus\":1,\"speed\":500," + - "\"minRam\":536870912,\"maxRam\":536870912,\"arch\":\"x86_64\"," + - "\"os\":\"CentOS 6.0 (64-bit)\",\"bootArgs\":\"\",\"rebootOnCrash\":false," + - "\"enableHA\":false,\"limitCpuUse\":false,\"vncPassword\":\"31f82f29aff646eb\"," + - "\"params\":{},\"uuid\":\"8b030b6a-0243-440a-8cc5-45d08815ca11\"" + - ",\"disks\":[" + - "{\"data\":" + getSampleVolumeObjectTO() + ",\"diskSeq\":0,\"type\":\"ROOT\"}," + - "{\"diskSeq\":1,\"type\":\"ISO\"}" + - "]," + - "\"nics\":[" + - "{\"deviceId\":0,\"networkRateMbps\":100,\"defaultNic\":true,\"uuid\":\"99cb4813-23af-428c-a87a-2d1899be4f4b\"," + - "\"ip\":\"10.1.1.67\",\"netmask\":\"255.255.255.0\",\"gateway\":\"10.1.1.1\"," + - "\"mac\":\"02:00:51:2c:00:0e\",\"dns1\":\"4.4.4.4\",\"broadcastType\":\"Vlan\",\"type\":\"Guest\"," + - "\"broadcastUri\":\"vlan://261\",\"isolationUri\":\"vlan://261\",\"isSecurityGroupEnabled\":false}" + - "]},\"contextMap\":{},\"wait\":0}"; - return sample; - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +using System; +using CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2; +using System.Management; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using System.IO; +using log4net; +using HypervResource; +using CloudStack.Plugin.AgentShell; +using System.Collections.Generic; +using NSubstitute; +using System.Web.Http; +using Xunit; + +namespace ServerResource.Tests +{ + public class HypervResourceController1Test + { + protected static string testCifsUrl = AgentSettings.Default.testCifsUrl; + protected static string testCifsPath = AgentSettings.Default.testCifsPath; + protected static String testPrimaryDataStoreHost = HypervResourceController.config.StorageIpAddress; + protected static String testS3TemplateName = AgentSettings.Default.testS3TemplateName; + protected static String testCifsTemplateName = AgentSettings.Default.testS3TemplateName; + protected static String testSystemVMTemplateName = AgentSettings.Default.testSystemVMTemplateName; + protected static String testSystemVMTemplateNameNoExt = AgentSettings.Default.testSystemVMTemplateNameNoExt; + protected static String testLocalStoreUUID = "5fe2bad3-d785-394e-9949-89786b8a63d2"; + protected static String testLocalStorePath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "storagepool"); + protected static String testSecondaryStoreLocalPath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "secondary"); + + // TODO: differentiate between NFS and HTTP template URLs. + protected static String testSampleTemplateUUID = "TestCopiedLocalTemplate.vhdx"; + protected static String testSampleTemplateURL = testSampleTemplateUUID; + + // test volumes are both a minimal size vhdx. Changing the extension to .vhd makes on corrupt. + protected static String testSampleVolumeWorkingUUID = "TestVolumeLegit.vhdx"; + protected static String testSampleVolumeCorruptUUID = "TestVolumeCorrupt.vhd"; + protected static String testSampleVolumeTempUUID = "TestVolumeTemp.vhdx"; + protected static String testSampleVolumeTempUUIDNoExt = "TestVolumeTemp"; + protected static String testSampleVolumeWorkingURIJSON; + protected static String testSampleVolumeCorruptURIJSON; + protected static String testSampleVolumeTempURIJSON; + + protected static String testSampleTemplateURLJSON; + protected static String testLocalStorePathJSON; + + protected static IWmiCallsV2 wmiCallsV2; + + + private static ILog s_logger = LogManager.GetLogger(typeof(HypervResourceController1Test)); + + /// + /// Test WmiCalls to which incoming HTTP POST requests are dispatched. + /// + /// TODO: revise beyond first approximation + /// First approximation is a quick port of the existing Java tests for Hyper-V server resource. + /// A second approximation would use the AgentShell settings files directly. + /// A third approximation would look to invoke ServerResource methods via an HTTP request + /// + + public HypervResourceController1Test() + { + wmiCallsV2 = Substitute.For(); + //AgentService.ConfigServerResource(); + HypervResourceController.config.PrivateMacAddress = AgentSettings.Default.private_mac_address; + HypervResourceController.config.PrivateNetmask = AgentSettings.Default.private_ip_netmask; + HypervResourceController.config.StorageIpAddress = HypervResourceController.config.PrivateIpAddress; + HypervResourceController.config.StorageMacAddress = HypervResourceController.config.PrivateMacAddress; + HypervResourceController.config.StorageNetmask = HypervResourceController.config.PrivateNetmask; + + + // Used to create existing StoragePool in preparation for the ModifyStoragePool + testLocalStoreUUID = AgentSettings.Default.local_storage_uuid.ToString(); + + // Make sure secondary store is available. + string fullPath = Path.GetFullPath(testSecondaryStoreLocalPath); + s_logger.Info("Test secondary storage in " + fullPath); + DirectoryInfo testSecondarStoreDir = new DirectoryInfo(fullPath); + if (!testSecondarStoreDir.Exists) + { + try + { + testSecondarStoreDir.Create(); + } + catch (System.IO.IOException ex) + { + throw new NotImplementedException("Need to be able to create the folder " + testSecondarStoreDir.FullName + " failed due to " + ex.Message); + } + } + + // Convert to secondary storage string to canonical path + testSecondaryStoreLocalPath = testSecondarStoreDir.FullName; + AgentSettings.Default.local_secondary_storage_path = testSecondaryStoreLocalPath; + + // Make sure local primary storage is available + DirectoryInfo testPoolDir = new DirectoryInfo(testLocalStorePath); + //Assert.True(testPoolDir.Exists, "To simulate local file system Storage Pool, you need folder at " + testPoolDir.FullName); + + // Convert to local primary storage string to canonical path + testLocalStorePath = testPoolDir.FullName; + AgentSettings.Default.local_storage_path = testLocalStorePath; + + // Clean up old test files in local storage folder + FileInfo testVolWorks = new FileInfo(Path.Combine(testLocalStorePath, testSampleVolumeWorkingUUID)); + // Assert.True(testVolWorks.Exists, "Create a working virtual disk at " + testVolWorks.FullName); + + testSampleTemplateURLJSON = JsonConvert.SerializeObject(testSampleTemplateUUID); + s_logger.Info("Created " + testSampleTemplateURLJSON + " in local storage."); + + + // Capture other JSON encoded paths + testSampleVolumeWorkingURIJSON = Newtonsoft.Json.JsonConvert.SerializeObject(testVolWorks.FullName); + testLocalStorePathJSON = JsonConvert.SerializeObject(testLocalStorePath); + + // TODO: may need to initialise the server resource in future. + // s_hypervresource.initialize(); + + // Verify sample template is in place storage pool + s_logger.Info("setUp complete, sample StoragePool at " + testLocalStorePathJSON + + " sample template at " + testSampleTemplateURLJSON); + } + + private String CreateTestDiskImageFromExistingImage(FileInfo srcFile, + String dstPath, + String dstFileName) + { + var newFullname = Path.Combine(dstPath, dstFileName); + var newFileInfo = new FileInfo(newFullname); + if (!newFileInfo.Exists) + { + newFileInfo = srcFile.CopyTo(newFullname); + } + newFileInfo.Refresh(); + Assert.True(newFileInfo.Exists, "Attempted to create " + newFullname + " from " + newFileInfo.FullName); + + return JsonConvert.SerializeObject(newFileInfo.FullName); + } + + [Fact] + public void TestCreateCommand() + { + DirectoryInfo localStorePath = new DirectoryInfo(testLocalStorePath); + if (!localStorePath.Exists) + { + try + { + localStorePath.Create(); + } + catch (System.IO.IOException ex) + { + throw new NotImplementedException("Need to be able to create the folder " + localStorePath.FullName + " failed due to " + ex.Message); + } + } + + FileInfo sampleTemplateFile = new FileInfo(Path.Combine(testLocalStorePath, testSampleTemplateUUID)); + if (!sampleTemplateFile.Exists) + { + //Create a file to write to. + using (StreamWriter sw = sampleTemplateFile.CreateText()) + { + sw.WriteLine("This is fake template file for test"); + } + } + var counter = 0; + wmiCallsV2.When(x => x.CreateDynamicVirtualHardDisk(Arg.Any(), Arg.Any())).Do(x => counter++); + // TODO: Need sample to update the test. + // Arrange + String createCmd = "{\"volId\":10,\"pool\":{\"id\":201,\"uuid\":\"" + testLocalStoreUUID + "\",\"host\":\"" + HypervResourceController.config.StorageIpAddress + "\"" + + ",\"path\":" + testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"},\"diskCharacteristics\":{\"size\":0," + + "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-9\",\"useLocalStorage\":true,\"recreatable\":true,\"diskOfferingId\":11," + + "\"volumeId\":10,\"hyperType\":\"Hyperv\"},\"templateUrl\":" + testSampleTemplateURLJSON + ",\"contextMap\":{},\"wait\":0}"; + dynamic jsonCreateCmd = JsonConvert.DeserializeObject(createCmd); + HypervResourceController rsrcServer = new HypervResourceController(); + HypervResourceController.wmiCallsV2 = wmiCallsV2; + + Assert.True(Directory.Exists(testLocalStorePath), testLocalStorePath + " does not exist "); + string filePath = Path.Combine(testLocalStorePath, (string)JsonConvert.DeserializeObject(testSampleTemplateURLJSON)); + Assert.True(File.Exists(filePath), "The template we make volumes from is missing from path " + filePath); + int fileCount = Directory.GetFiles(testLocalStorePath).Length; + s_logger.Debug(" test local store has " + fileCount + "files"); + + // Act + // Test requires there to be a template at the tempalteUrl, which is its location in the local file system. + dynamic jsonResult = rsrcServer.CreateCommand(jsonCreateCmd); + s_logger.Debug("CreateDynamicVirtualHardDisk method is called " + counter + " times"); + + //Assert.Equal(counter, 1); + + JObject ansAsProperty2 = jsonResult[0]; + dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.CreateAnswer); + Assert.NotNull(ans); + Assert.True((bool)ans.result, "Failed to CreateCommand due to " + (string)ans.result); + Assert.Equal(Directory.GetFiles(testLocalStorePath).Length, fileCount + 1); + FileInfo newFile = new FileInfo((string)ans.volume.path); + Assert.True(newFile.Length > 0, "The new file should have a size greater than zero"); + newFile.Delete(); + sampleTemplateFile.Delete(); + } + + [Fact] + public void TestDestroyCommand() + { + testSampleVolumeTempURIJSON = "\"storagepool\""; + // Arrange + String destroyCmd = //"{\"volume\":" + getSampleVolumeObjectTO() + "}"; + "{\"volume\":{\"name\":\"" + testSampleVolumeTempUUIDNoExt + + "\",\"storagePoolType\":\"Filesystem\"," + + "\"mountPoint\":" + + testLocalStorePathJSON + + ",\"path\":" + testSampleVolumeTempURIJSON + + ",\"storagePoolUuid\":\"" + testLocalStoreUUID + + "\"," + + "\"type\":\"ROOT\",\"id\":9,\"size\":0}}"; + + ImageManagementService imgmgr = new ImageManagementService(); + wmiCallsV2.GetImageManagementService().Returns(imgmgr); + + HypervResourceController rsrcServer = new HypervResourceController(); + HypervResourceController.wmiCallsV2 = wmiCallsV2; + + dynamic jsonDestroyCmd = JsonConvert.DeserializeObject(destroyCmd); + + // Act + dynamic destroyAns = rsrcServer.DestroyCommand(jsonDestroyCmd); + + // Assert + JObject ansAsProperty2 = destroyAns[0]; + dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.Answer); + String path = jsonDestroyCmd.volume.path; + Assert.True((bool)ans.result, "DestroyCommand did not succeed " + ans.details); + Assert.True(!File.Exists(path), "Failed to delete file " + path); + } + + [Fact] + public void TestStartCommand() + { + ComputerSystem system = new ComputerSystem(); + wmiCallsV2.DeployVirtualMachine(Arg.Any(), Arg.Any()).Returns(system); + + // Arrange + HypervResourceController rsrcServer = new HypervResourceController(); + HypervResourceController.wmiCallsV2 = wmiCallsV2; + String sample = getSampleStartCommand(); + + + dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample); + + // Act + dynamic startAns = rsrcServer.StartCommand(jsonStartCmd); + + // Assert + Assert.NotNull(startAns[0][CloudStackTypes.StartAnswer]); + Assert.True((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details); + + Assert.Null((string)startAns[0][CloudStackTypes.StartAnswer].details); + } + + [Fact] + public void TestStopCommand() + { + //string vmName = "Test VM"; + var counter = 0; + wmiCallsV2.When(x => x.DestroyVm(Arg.Any())).Do(x => counter++); + + // Arrange + HypervResourceController rsrcServer = new HypervResourceController(); + HypervResourceController.wmiCallsV2 = wmiCallsV2; + + String sampleStop = "{\"isProxy\":false,\"vmName\":\"i-2-17-VM\",\"contextMap\":{},\"checkBeforeCleanup\":false,\"wait\":0}"; + dynamic jsonStopCmd = JsonConvert.DeserializeObject(sampleStop); + + // Act + dynamic stopAns = rsrcServer.StopCommand(jsonStopCmd); + + // Assert VM is gone! + Assert.NotNull(stopAns[0][CloudStackTypes.StopAnswer]); + Assert.True((bool)stopAns[0][CloudStackTypes.StopAnswer].result, "StopCommand did not succeed " + stopAns[0][CloudStackTypes.StopAnswer].details); + + Assert.Null((string)stopAns[0][CloudStackTypes.StopAnswer].details); + Assert.Equal(counter, 1); + } + + public static String getSamplePrimaryDataStoreInfo() + { + String samplePrimaryDataStoreInfo = + "{\"org.apache.cloudstack.storage.to.PrimaryDataStoreTO\":" + + "{\"uuid\":\"" + testLocalStoreUUID + "\"," + + "\"id\":201," + + "\"host\":\"" + testPrimaryDataStoreHost + "\"," + + "\"type\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO + "\"poolType\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO + "\"path\":" + testLocalStorePathJSON + "," + + "\"port\":0}" + + "}"; + return samplePrimaryDataStoreInfo; + } + + public static String getSampleVolumeObjectTO() + { + String sampleVolumeObjectTO = + "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + + "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + + "\"volumeType\":\"ROOT\"," + + "\"format\":\"VHDX\"," + + "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + + "\"name\":\"" + testSampleVolumeTempUUIDNoExt + "\"," + + "\"size\":52428800," + + "\"volumeId\":10," + + // "\"vmName\":\"i-3-5-VM\"," + // TODO: do we have to fill in the vmName? + "\"accountId\":3,\"id\":10}" + + "}"; // end of destTO + return sampleVolumeObjectTO; + } + + public static String getSampleStartCommand() + { + String sample = "{\"vm\":{\"id\":17,\"name\":\"i-2-17-VM\",\"type\":\"User\",\"cpus\":1,\"speed\":500," + + "\"minRam\":536870912,\"maxRam\":536870912,\"arch\":\"x86_64\"," + + "\"os\":\"CentOS 6.0 (64-bit)\",\"bootArgs\":\"\",\"rebootOnCrash\":false," + + "\"enableHA\":false,\"limitCpuUse\":false,\"vncPassword\":\"31f82f29aff646eb\"," + + "\"params\":{},\"uuid\":\"8b030b6a-0243-440a-8cc5-45d08815ca11\"" + + ",\"disks\":[" + + "{\"data\":" + getSampleVolumeObjectTO() + ",\"diskSeq\":0,\"type\":\"ROOT\"}," + + "{\"diskSeq\":1,\"type\":\"ISO\"}" + + "]," + + "\"nics\":[" + + "{\"deviceId\":0,\"networkRateMbps\":100,\"defaultNic\":true,\"uuid\":\"99cb4813-23af-428c-a87a-2d1899be4f4b\"," + + "\"ip\":\"10.1.1.67\",\"netmask\":\"255.255.255.0\",\"gateway\":\"10.1.1.1\"," + + "\"mac\":\"02:00:51:2c:00:0e\",\"dns1\":\"4.4.4.4\",\"broadcastType\":\"Vlan\",\"type\":\"Guest\"," + + "\"broadcastUri\":\"vlan://261\",\"isolationUri\":\"vlan://261\",\"isSecurityGroupEnabled\":false}" + + "]},\"contextMap\":{},\"wait\":0}"; + return sample; + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceControllerTest.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceControllerTest.cs index f816309c820c..288d1a1c4068 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceControllerTest.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/ServerResource.Tests/HypervResourceControllerTest.cs @@ -1,1147 +1,1147 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -using System; -using CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION; -using System.Management; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; -using System.IO; -using log4net; -using HypervResource; -using CloudStack.Plugin.AgentShell; -using System.Collections.Generic; -using System.Xml; -using Xunit; - -namespace ServerResource.Tests -{ - public class HypervResourceControllerTest - { - protected static string testCifsUrl = AgentSettings.Default.testCifsUrl; - protected static string testCifsPath = AgentSettings.Default.testCifsPath; - protected static String testPrimaryDataStoreHost = HypervResourceController.config.StorageIpAddress; - protected static String testS3TemplateName = AgentSettings.Default.testS3TemplateName; - protected static String testCifsTemplateName = AgentSettings.Default.testS3TemplateName; - protected static String testSystemVMTemplateName = AgentSettings.Default.testSystemVMTemplateName; - protected static String testSystemVMTemplateNameNoExt = AgentSettings.Default.testSystemVMTemplateNameNoExt; - protected static String testLocalStoreUUID = "5fe2bad3-d785-394e-9949-89786b8a63d2"; - protected static String testLocalStorePath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "storagepool"); - protected static String testSecondaryStoreLocalPath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "secondary"); - - // TODO: differentiate between NFS and HTTP template URLs. - protected static String testSampleTemplateUUID = "TestCopiedLocalTemplate.vhdx"; - protected static String testSampleTemplateURL = testSampleTemplateUUID; - - // test volumes are both a minimal size vhdx. Changing the extension to .vhd makes on corrupt. - protected static String testSampleVolumeWorkingUUID = "TestVolumeLegit.vhdx"; - protected static String testSampleVolumeCorruptUUID = "TestVolumeCorrupt.vhd"; - protected static String testSampleVolumeTempUUID = "TestVolumeTemp.vhdx"; - protected static String testSampleVolumeTempUUIDNoExt = "TestVolumeTemp"; - protected static String testSampleVolumeWorkingURIJSON; - protected static String testSampleVolumeCorruptURIJSON; - protected static String testSampleVolumeTempURIJSON; - - protected static String testSampleTemplateURLJSON; - protected static String testLocalStorePathJSON; - - protected static WmiCallsV2 wmiCallsV2 = new WmiCallsV2(); - - private static ILog s_logger = LogManager.GetLogger(typeof(HypervResourceControllerTest)); - - /// - /// Test WmiCalls to which incoming HTTP POST requests are dispatched. - /// - /// TODO: revise beyond first approximation - /// First approximation is a quick port of the existing Java tests for Hyper-V server resource. - /// A second approximation would use the AgentShell settings files directly. - /// A third approximation would look to invoke ServerResource methods via an HTTP request - /// - public HypervResourceControllerTest() - { - AgentService.ConfigServerResource(); - HypervResourceController.config.PrivateMacAddress = AgentSettings.Default.private_mac_address; - HypervResourceController.config.PrivateNetmask = AgentSettings.Default.private_ip_netmask; - HypervResourceController.config.StorageIpAddress = HypervResourceController.config.PrivateIpAddress; - HypervResourceController.config.StorageMacAddress = HypervResourceController.config.PrivateMacAddress; - HypervResourceController.config.StorageNetmask = HypervResourceController.config.PrivateNetmask; - - - // Used to create existing StoragePool in preparation for the ModifyStoragePool - testLocalStoreUUID = AgentSettings.Default.local_storage_uuid.ToString(); - - // Make sure secondary store is available. - string fullPath = Path.GetFullPath(testSecondaryStoreLocalPath); - s_logger.Info("Test secondary storage in " + fullPath); - DirectoryInfo testSecondarStoreDir = new DirectoryInfo(fullPath); - if (!testSecondarStoreDir.Exists) - { - try - { - testSecondarStoreDir.Create(); - } - catch (System.IO.IOException ex) - { - throw new NotImplementedException("Need to be able to create the folder " + testSecondarStoreDir.FullName + " failed due to " + ex.Message); - } - } - - // Convert to secondary storage string to canonical path - testSecondaryStoreLocalPath = testSecondarStoreDir.FullName; - AgentSettings.Default.local_secondary_storage_path = testSecondaryStoreLocalPath; - - // Make sure local primary storage is available - DirectoryInfo testPoolDir = new DirectoryInfo(testLocalStorePath); - Assert.True(testPoolDir.Exists, "To simulate local file system Storage Pool, you need folder at " + testPoolDir.FullName); - - // Convert to local primary storage string to canonical path - testLocalStorePath = testPoolDir.FullName; - AgentSettings.Default.local_storage_path = testLocalStorePath; - - // Clean up old test files in local storage folder - FileInfo testVolWorks = new FileInfo(Path.Combine(testLocalStorePath, testSampleVolumeWorkingUUID)); - Assert.True(testVolWorks.Exists, "Create a working virtual disk at " + testVolWorks.FullName); - - - // Delete all temporary files in local folder save the testVolWorks - foreach (var file in testPoolDir.GetFiles()) - { - if (file.FullName == testVolWorks.FullName) - { - continue; - } - file.Delete(); - file.Refresh(); - Assert.False(file.Exists, "removed file from previous test called " + file.FullName); - } - - // Recreate starting point files for test, and record JSON encoded paths for each ... - testSampleVolumeTempURIJSON = CreateTestDiskImageFromExistingImage(testVolWorks, testLocalStorePath, testSampleVolumeTempUUID); - s_logger.Info("Created " + testSampleVolumeTempURIJSON); - testSampleVolumeCorruptURIJSON = CreateTestDiskImageFromExistingImage(testVolWorks, testLocalStorePath, testSampleVolumeCorruptUUID); - s_logger.Info("Created " + testSampleVolumeCorruptURIJSON); - CreateTestDiskImageFromExistingImage(testVolWorks, testLocalStorePath, testSampleTemplateUUID); - testSampleTemplateURLJSON = JsonConvert.SerializeObject(testSampleTemplateUUID); - s_logger.Info("Created " + testSampleTemplateURLJSON + " in local storage."); - - // ... including a secondary storage template: - CreateTestDiskImageFromExistingImage(testVolWorks, testSecondarStoreDir.FullName, "af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx"); - s_logger.Info("Created " + "af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx" + " in secondary (NFS) storage."); - - - // Capture other JSON encoded paths - testSampleVolumeWorkingURIJSON = Newtonsoft.Json.JsonConvert.SerializeObject(testVolWorks.FullName); - testLocalStorePathJSON = JsonConvert.SerializeObject(testLocalStorePath); - - // TODO: may need to initialise the server resource in future. - // s_hypervresource.initialize(); - - // Verify sample template is in place storage pool - s_logger.Info("setUp complete, sample StoragePool at " + testLocalStorePathJSON - + " sample template at " + testSampleTemplateURLJSON); - } - - private String CreateTestDiskImageFromExistingImage(FileInfo srcFile, - String dstPath, - String dstFileName) - { - var newFullname = Path.Combine(dstPath, dstFileName); - var newFileInfo = new FileInfo(newFullname); - if (!newFileInfo.Exists) - { - newFileInfo = srcFile.CopyTo(newFullname); - } - newFileInfo.Refresh(); - Assert.True(newFileInfo.Exists, "Attempted to create " + newFullname + " from " + newFileInfo.FullName); - - return JsonConvert.SerializeObject(newFileInfo.FullName); - } - - [Fact(Skip="these are functional tests")] - public void TestPrimaryStorageDownloadCommandHTTP() - { - string downloadURI = "https://s3-eu-west-1.amazonaws.com/cshv3eu/SmallDisk.vhdx"; - corePrimaryStorageDownloadCommandTestCycle(downloadURI); - } - - private void corePrimaryStorageDownloadCommandTestCycle(string downloadURI) - { - // Arrange - HypervResourceController rsrcServer = new HypervResourceController(); - dynamic jsonPSDCmd = JsonConvert.DeserializeObject(samplePrimaryDownloadCommand()); - jsonPSDCmd.url = downloadURI; - - // Act - dynamic jsonResult = rsrcServer.PrimaryStorageDownloadCommand(jsonPSDCmd); - - // Assert - JObject ansAsProperty = jsonResult[0]; - dynamic ans = ansAsProperty.GetValue(CloudStackTypes.PrimaryStorageDownloadAnswer); - Assert.True((bool)ans.result, "PrimaryStorageDownloadCommand did not succeed " + ans.details); - - // Test that URL of downloaded template works for file creation. - dynamic jsonCreateCmd = JsonConvert.DeserializeObject(CreateCommandSample()); - jsonCreateCmd.templateUrl = ans.installPath; - dynamic jsonAns2 = rsrcServer.CreateCommand(jsonCreateCmd); - JObject ansAsProperty2 = jsonAns2[0]; - dynamic ans2 = ansAsProperty2.GetValue(CloudStackTypes.CreateAnswer); - - Assert.True((bool)ans2.result, (string)ans2.details); - - FileInfo newFile = new FileInfo((string)ans2.volume.path); - Assert.True(newFile.Length > 0, "The new file should have a size greater than zero"); - newFile.Delete(); - } - - private string samplePrimaryDownloadCommand() - { - String cmdJson = "{\"localPath\":" + testLocalStorePathJSON + - ",\"poolUuid\":\"" + testLocalStoreUUID + "\",\"poolId\":201," + - "\"secondaryStorageUrl\":\"nfs://10.70.176.36/mnt/cshv3/secondarystorage\"," + - "\"primaryStorageUrl\":\"nfs://" + HypervResourceController.config.StorageIpAddress + "E:\\\\Disks\\\\Disks\"," + - "\"url\":\"nfs://10.70.176.36/mnt/cshv3/secondarystorage/template/tmpl//2/204//af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx\"," + - "\"format\":\"VHDX\",\"accountId\":2,\"name\":\"204-2-5a1db1ac-932b-3e7e-a0e8-5684c72cb862\"" + - ",\"contextMap\":{},\"wait\":10800}"; - return cmdJson; - } - - public string CreateCommandSample() - { - String sample = "{\"volId\":17,\"pool\":{\"id\":201,\"uuid\":\"" + testLocalStoreUUID + "\",\"host\":\"" + HypervResourceController.config.StorageIpAddress + "\"" + - ",\"path\":" + testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"},\"diskCharacteristics\":{\"size\":0," + - "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-15\",\"useLocalStorage\":true,\"recreatable\":true,\"diskOfferingId\":11," + - "\"volumeId\":17,\"hyperType\":\"Hyperv\"},\"templateUrl\":" + testSampleTemplateURLJSON + ",\"wait\":0}"; - return sample; - } - - [Fact(Skip="these are functional tests")] - public void TestDestroyCommand() - { - // Arrange - String sampleVolume = getSampleVolumeObjectTO(); - String destroyCmd = //"{\"volume\":" + getSampleVolumeObjectTO() + "}"; - "{\"volume\":{\"name\":\"" + testSampleVolumeTempUUIDNoExt - + "\",\"storagePoolType\":\"Filesystem\"," - + "\"mountPoint\":" - + testLocalStorePathJSON - + ",\"path\":" + testSampleVolumeTempURIJSON - + ",\"storagePoolUuid\":\"" + testLocalStoreUUID - + "\"," - + "\"type\":\"ROOT\",\"id\":9,\"size\":0}}"; - - HypervResourceController rsrcServer = new HypervResourceController(); - dynamic jsonDestroyCmd = JsonConvert.DeserializeObject(destroyCmd); - - // Act - dynamic destroyAns = rsrcServer.DestroyCommand(jsonDestroyCmd); - - // Assert - JObject ansAsProperty2 = destroyAns[0]; - dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.Answer); - String path = jsonDestroyCmd.volume.path; - Assert.True((bool)ans.result, "DestroyCommand did not succeed " + ans.details); - Assert.True(!File.Exists(path), "Failed to delete file " + path); - } - - [Fact(Skip="these are functional tests")] - public void TestCreateCommand() - { - // TODO: Need sample to update the test. - // Arrange - String createCmd = "{\"volId\":10,\"pool\":{\"id\":201,\"uuid\":\"" + testLocalStoreUUID + "\",\"host\":\"" + HypervResourceController.config.StorageIpAddress + "\"" + - ",\"path\":" + testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"},\"diskCharacteristics\":{\"size\":0," + - "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-9\",\"useLocalStorage\":true,\"recreatable\":true,\"diskOfferingId\":11," + - "\"volumeId\":10,\"hyperType\":\"Hyperv\"},\"templateUrl\":" + testSampleTemplateURLJSON + ",\"contextMap\":{},\"wait\":0}"; - dynamic jsonCreateCmd = JsonConvert.DeserializeObject(createCmd); - HypervResourceController rsrcServer = new HypervResourceController(); - - Assert.True(Directory.Exists(testLocalStorePath)); - string filePath = Path.Combine(testLocalStorePath, (string)JsonConvert.DeserializeObject(testSampleTemplateURLJSON)); - Assert.True(File.Exists(filePath), "The template we make volumes from is missing from path " + filePath); - int fileCount = Directory.GetFiles(testLocalStorePath).Length; - s_logger.Debug(" test local store has " + fileCount + "files"); - - // Act - // Test requires there to be a template at the tempalteUrl, which is its location in the local file system. - dynamic jsonResult = rsrcServer.CreateCommand(jsonCreateCmd); - - JObject ansAsProperty2 = jsonResult[0]; - dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.CreateAnswer); - Assert.NotNull(ans); - Assert.True((bool)ans.result, "Failed to CreateCommand due to " + (string)ans.result); - Assert.Equal(Directory.GetFiles(testLocalStorePath).Length, fileCount + 1); - FileInfo newFile = new FileInfo((string)ans.volume.path); - Assert.True(newFile.Length > 0, "The new file should have a size greater than zero"); - newFile.Delete(); - } - - /// - /// Possible additional tests: place an ISO in the drive - /// - [Fact(Skip="these are functional tests")] - public void TestStartStopCommand() - { - string vmName = TestStartCommand(); - TestStopCommand(vmName); - } - - public static String getSamplePrimaryDataStoreInfo() - { - String samplePrimaryDataStoreInfo = - "{\"org.apache.cloudstack.storage.to.PrimaryDataStoreTO\":" + - "{\"uuid\":\"" + testLocalStoreUUID + "\"," + - "\"id\":201," + - "\"host\":\"" + testPrimaryDataStoreHost + "\"," + - "\"type\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO - "\"poolType\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO - "\"path\":" + testLocalStorePathJSON + "," + - "\"port\":0}" + - "}"; - return samplePrimaryDataStoreInfo; - } - - public static String getSampleVolumeObjectTO() - { - String sampleVolumeObjectTO = - "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + - "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + - "\"volumeType\":\"ROOT\"," + - "\"format\":\"VHDX\"," + - "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + - "\"name\":\"" + testSampleVolumeTempUUIDNoExt + "\"," + - "\"size\":52428800," + - "\"volumeId\":10," + - // "\"vmName\":\"i-3-5-VM\"," + // TODO: do we have to fill in the vmName? - "\"accountId\":3,\"id\":10}" + - "}"; // end of destTO - return sampleVolumeObjectTO; - } - - public static String getSampleStartCommand() - { - String sample = "{\"vm\":{\"id\":17,\"name\":\"i-2-17-VM\",\"type\":\"User\",\"cpus\":1,\"speed\":500," + - "\"minRam\":536870912,\"maxRam\":536870912,\"arch\":\"x86_64\"," + - "\"os\":\"CentOS 6.0 (64-bit)\",\"bootArgs\":\"\",\"rebootOnCrash\":false," + - "\"enableHA\":false,\"limitCpuUse\":false,\"vncPassword\":\"31f82f29aff646eb\"," + - "\"params\":{},\"uuid\":\"8b030b6a-0243-440a-8cc5-45d08815ca11\"" + - ",\"disks\":[" + - "{\"data\":" + getSampleVolumeObjectTO() + ",\"diskSeq\":0,\"type\":\"ROOT\"}," + - "{\"diskSeq\":1,\"type\":\"ISO\"}" + - "]," + - "\"nics\":[" + - "{\"deviceId\":0,\"networkRateMbps\":100,\"defaultNic\":true,\"uuid\":\"99cb4813-23af-428c-a87a-2d1899be4f4b\"," + - "\"ip\":\"10.1.1.67\",\"netmask\":\"255.255.255.0\",\"gateway\":\"10.1.1.1\"," + - "\"mac\":\"02:00:51:2c:00:0e\",\"dns1\":\"4.4.4.4\",\"broadcastType\":\"Vlan\",\"type\":\"Guest\"," + - "\"broadcastUri\":\"vlan://261\",\"isolationUri\":\"vlan://261\",\"isSecurityGroupEnabled\":false}" + - "]},\"contextMap\":{},\"wait\":0}"; - return sample; - } - - - [Fact(Skip="these are functional tests")] - public void TestCopyCommandFromCifs() - { - // Arrange - string sampleCopyCommandForTemplateDownload = - #region string_literal - // org.apache.cloudstack.storage.command.CopyCommand - "{\"srcTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{\"path\":\"" + testCifsPath + "\"," + - "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + - "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + - "\"id\":206," + - "\"format\":\"VHDX\"," + - "\"accountId\":2," + - "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + - "\"hvm\":true," + - "\"displayText\":\"OS031\"," + - "\"imageDataStore\":" + - "{\"com.cloud.agent.api.to.NfsTO\":" + - "{\"_url\":\"" + testCifsUrl + "\"," + // Unique item here - "\"_role\":\"Image\"}" + - "}," + // end of imageDataStore - "\"hypervisorType\":\"Hyperv\"," + - "\"name\":\"" + testS3TemplateName + "\"}" + - "}," + // end of srcTO - "\"destTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{" + - "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + - "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + - "\"id\":206," + - "\"format\":\"VHDX\"," + - "\"accountId\":2," + - "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + - "\"hvm\":true," + - "\"displayText\":\"Test of CIFS Download\"," + - "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + // end of imageDataStore - "\"name\":\"" + testS3TemplateName + "\"," + - "\"hypervisorType\":\"Hyperv\"}" + - "}," +// end of destTO - "\"wait\":10800}"; // end of CopyCommand - #endregion - - HypervResourceController rsrcServer; - dynamic jsonDownloadCopyCmd; - string dwnldDest; - dynamic jsonCloneCopyCmd; - string newVolName; - CopyCommandTestSetupCifs(null, sampleCopyCommandForTemplateDownload, out rsrcServer, out jsonDownloadCopyCmd, out dwnldDest, out jsonCloneCopyCmd, out newVolName); - - // Act & Assert - DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); - - // Repeat to verify ability to detect existing file. - DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); - - File.Delete(dwnldDest); - } - - [Fact(Skip="these are functional tests")] - public void TestCopyCommand() - { - // Arrange - string sampleCopyCommandToCreateVolumeFromTemplate = - #region string_literal - // org.apache.cloudstack.storage.command.CopyCommand - "{\"srcTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{" + - "\"origUrl\":\"http://people.apache.org/~bhaisaab/vms/ttylinux_pv.vhd\"," + - "\"uuid\":\"9873f1c0-bdcc-11e2-8baa-ea85dab5fcd0\"," + - "\"id\":5," + - "\"format\":\"VHDX\"," + - "\"accountId\":1," + - "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + - "\"hvm\":false," + - "\"displayText\":\"tiny Linux\"," + - "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + - "\"name\":\"" + testS3TemplateName + "\"}" + - "}," + // end of srcTO - "\"destTO\":" + - "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + - "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + - "\"volumeType\":\"ROOT\"," + - "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + - "\"name\":\"ROOT-5\"," + - "\"size\":52428800," + - "\"volumeId\":10," + - "\"vmName\":\"i-3-5-VM\"," + - "\"accountId\":3," + - "\"id\":10 }" + - "}," + // end of destTO - "\"wait\":0}"; // end of Copy Command - #endregion - //"name":"ROOT-8","size":140616708,"volumeId":8,"vmName":"s-8-VM","accountId":1,"id":8}},"contextMap":{},"wait":0} - - string sampleCopyCommandForTemplateDownload = - #region string_literal - // org.apache.cloudstack.storage.command.CopyCommand - "{\"srcTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{\"path\":\"" + testS3TemplateName + ".vhdx" + "\"," + - "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + - "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + - "\"id\":206," + - "\"format\":\"VHDX\"," + - "\"accountId\":2," + - "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + - "\"hvm\":true," + - "\"displayText\":\"OS031\"," + - "\"imageDataStore\":" + - "{\"com.cloud.agent.api.to.S3TO\":" + - "{\"id\":1," + - "\"uuid\":\"95a64c8f-2128-4502-b5b4-0d7aa77406d2\"," + - "\"accessKey\":\"" + AgentSettings.Default.testS3AccessKey + "\"," + - "\"secretKey\":\"" + AgentSettings.Default.testS3SecretKey + "\"," + - "\"endPoint\":\"" + AgentSettings.Default.testS3Endpoint + "\"," + - "\"bucketName\":\"" + AgentSettings.Default.testS3Bucket + "\"," + - "\"httpsFlag\":false," + - "\"created\":\"May 19, 2013 4:17:25 PM\"}" + - "}," + // end of imageDataStore - "\"name\":\"" + testS3TemplateName + "\"}" + - "}," + // end of srcTO - "\"destTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{" + - "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + - "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + - "\"id\":206," + - "\"format\":\"VHDX\"," + - "\"accountId\":2," + - "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + - "\"hvm\":true," + - "\"displayText\":\"OS031\"," + - "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + // end of imageDataStore - "\"name\":\"" + testS3TemplateName + "\"}" + - "}," +// end of destTO - "\"wait\":10800}"; // end of CopyCommand - #endregion - - HypervResourceController rsrcServer; - dynamic jsonDownloadCopyCmd; - string dwnldDest; - dynamic jsonCloneCopyCmd; - string newVolName; - CopyCommandTestSetup(sampleCopyCommandToCreateVolumeFromTemplate, sampleCopyCommandForTemplateDownload, out rsrcServer, out jsonDownloadCopyCmd, out dwnldDest, out jsonCloneCopyCmd, out newVolName); - - // Act & Assert - DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); - CreateVolumeFromTemplate(rsrcServer, jsonCloneCopyCmd, newVolName); - - // Repeat to verify ability to detect existing file. - DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); - - File.Delete(dwnldDest); - File.Delete(newVolName); - } - - private static void CreateVolumeFromTemplate(HypervResourceController rsrcServer, dynamic jsonCloneCopyCmd, string newVolName) - { - dynamic copyResult = rsrcServer.CopyCommand(jsonCloneCopyCmd); - - // Assert - Assert.NotNull(copyResult[0][CloudStackTypes.CopyCmdAnswer]); - Assert.True((bool)copyResult[0][CloudStackTypes.CopyCmdAnswer].result, "CopyCommand did not succeed " + copyResult[0][CloudStackTypes.CopyCmdAnswer].details); - Assert.True(File.Exists(newVolName), "CopyCommand failed to generate " + newVolName); - } - - private static void DownloadTemplateToPrimaryStorage(HypervResourceController rsrcServer, dynamic jsonDownloadCopyCmd, string dwnldDest) - { - dynamic dwnldResult = rsrcServer.CopyCommand(jsonDownloadCopyCmd); - - // Assert - Assert.NotNull(dwnldResult[0][CloudStackTypes.CopyCmdAnswer]); - Assert.True((bool)dwnldResult[0][CloudStackTypes.CopyCmdAnswer].result, "CopyCommand did not succeed " + dwnldResult[0][CloudStackTypes.CopyCmdAnswer].details); - Assert.True(File.Exists(dwnldDest), "CopyCommand failed to generate " + dwnldDest); - } - - [Fact(Skip="these are functional tests")] - public void TestCopyCommandBz2Img() - { - // Arrange - string sampleCopyCommandToCreateVolumeFromTemplate = - #region string_literal - // org.apache.cloudstack.storage.command.CopyCommand - "{\"srcTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{" + - "\"origUrl\":\"http://people.apache.org/~bhaisaab/vms/ttylinux_pv.vhd\"," + - "\"uuid\":\"9873f1c0-bdcc-11e2-8baa-ea85dab5fcd0\"," + - "\"id\":5," + - "\"format\":\"VHD\"," + - "\"accountId\":1," + - "\"checksum\":\"f613f38c96bf039f2e5cbf92fa8ad4f8\"," + - "\"hvm\":false," + - "\"displayText\":\"tiny Linux\"," + - "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + - "\"name\":\"" + testSystemVMTemplateNameNoExt + "\"}" + - "}," + // end of srcTO - "\"destTO\":" + - "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + - "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + - "\"volumeType\":\"ROOT\"," + - "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + - "\"name\":\"ROOT-5\"," + - "\"size\":52428800," + - "\"volumeId\":10," + - "\"vmName\":\"i-3-5-VM\"," + - "\"accountId\":1," + - "\"id\":10}" + - "}," + // end of destTO - "\"wait\":0}"; // end of Copy Command - #endregion - - string sampleCopyCommandForTemplateDownload = - #region string_literal - // org.apache.cloudstack.storage.command.CopyCommand - "{\"srcTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{\"path\":\"" + testSystemVMTemplateName + "\"," + - "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + - "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + - "\"id\":206," + - "\"format\":\"VHD\"," + - "\"accountId\":1," + - "\"checksum\": \"f613f38c96bf039f2e5cbf92fa8ad4f8\"," + - "\"hvm\":true," + - "\"displayText\":\"OS031\"," + - "\"imageDataStore\":" + - "{\"com.cloud.agent.api.to.S3TO\":" + - "{\"id\":1," + - "\"uuid\":\"95a64c8f-2128-4502-b5b4-0d7aa77406d2\"," + - "\"accessKey\":\"" + AgentSettings.Default.testS3AccessKey + "\"," + - "\"secretKey\":\"" + AgentSettings.Default.testS3SecretKey + "\"," + - "\"endPoint\":\"" + AgentSettings.Default.testS3Endpoint + "\"," + - "\"bucketName\":\"" + AgentSettings.Default.testS3Bucket + "\"," + - "\"httpsFlag\":false," + - "\"created\":\"May 19, 2013 4:17:25 PM\"}" + - "}," + // end of imageDataStore - "\"name\":\"" + testSystemVMTemplateNameNoExt + "\"}" + - "}," + // end of srcTO - "\"destTO\":" + - "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + - "{" + - "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + - "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + - "\"id\":206," + - "\"format\":\"VHD\"," + - "\"accountId\":1," + - "\"checksum\": \"f613f38c96bf039f2e5cbf92fa8ad4f8\"," + - "\"hvm\":true," + - "\"displayText\":\"OS031\"," + - "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + // end of imageDataStore - "\"name\":\"" + testSystemVMTemplateNameNoExt + "\"}" + - "}," +// end of destTO - "\"wait\":10800}"; // end of CopyCommand - #endregion - - HypervResourceController rsrcServer; - dynamic jsonDownloadCopyCmd; - string dwnldDest; - dynamic jsonCloneCopyCmd; - string newVolName; - CopyCommandTestSetup(sampleCopyCommandToCreateVolumeFromTemplate, sampleCopyCommandForTemplateDownload, out rsrcServer, out jsonDownloadCopyCmd, out dwnldDest, out jsonCloneCopyCmd, out newVolName); - - // Act & Assert - DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); - CreateVolumeFromTemplate(rsrcServer, jsonCloneCopyCmd, newVolName); - - File.Delete(dwnldDest); - File.Delete(newVolName); - } - - private static void CopyCommandTestSetup(string sampleCopyCommandToCreateVolumeFromTemplate, string sampleCopyCommandForTemplateDownload, out HypervResourceController rsrcServer, out dynamic jsonDownloadCopyCmd, out string dwnldDest, out dynamic jsonCloneCopyCmd, out string newVolName) - { - rsrcServer = new HypervResourceController(); - jsonDownloadCopyCmd = JsonConvert.DeserializeObject(sampleCopyCommandForTemplateDownload); - TemplateObjectTO dwnldTemplate = TemplateObjectTO.ParseJson(jsonDownloadCopyCmd.destTO); - dwnldDest = dwnldTemplate.FullFileName; - - jsonCloneCopyCmd = JsonConvert.DeserializeObject(sampleCopyCommandToCreateVolumeFromTemplate); - VolumeObjectTO newVol = VolumeObjectTO.ParseJson(jsonCloneCopyCmd.destTO); - newVol.format = dwnldTemplate.format; - newVolName = dwnldTemplate.FullFileName; - - if (File.Exists(dwnldDest)) - { - File.Delete(dwnldDest); - } - if (File.Exists(newVolName)) - { - File.Delete(newVolName); - } - } - - private static void CopyCommandTestSetupCifs(string sampleCopyCommandToCreateVolumeFromTemplate, string sampleCopyCommandForTemplateDownload, out HypervResourceController rsrcServer, out dynamic jsonDownloadCopyCmd, out string dwnldDest, out dynamic jsonCloneCopyCmd, out string newVolName) - { - rsrcServer = new HypervResourceController(); - jsonDownloadCopyCmd = JsonConvert.DeserializeObject(sampleCopyCommandForTemplateDownload); - TemplateObjectTO dwnldTemplate = TemplateObjectTO.ParseJson(jsonDownloadCopyCmd.destTO); - dwnldDest = dwnldTemplate.FullFileName; - - if (File.Exists(dwnldDest)) - { - File.Delete(dwnldDest); - } - newVolName = null; - jsonCloneCopyCmd = null; - } - - [Fact(Skip="these are functional tests")] - public void TestModifyStoragePoolCommand() - { - // Create dummy folder - String folderName = Path.Combine(".", "Dummy"); - if (!Directory.Exists(folderName)) - { - Directory.CreateDirectory(folderName); - } - - var pool = new - { // From java class StorageFilerTO - type = Enum.GetName(typeof(StoragePoolType), StoragePoolType.Filesystem), - host = "127.0.0.1", - port = -1, - path = folderName, - uuid = Guid.NewGuid().ToString(), - userInfo = string.Empty // Used in future to hold credential - }; - - var cmd = new - { - add = true, - pool = pool, - localPath = folderName - }; - JToken tok = JToken.FromObject(cmd); - HypervResourceController controller = new HypervResourceController(); - - // Act - dynamic jsonResult = controller.ModifyStoragePoolCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.ModifyStoragePoolAnswer]; - Assert.True((bool)ans.result, (string)ans.details); // always succeeds - - // Clean up - var cmd2 = new - { - pool = pool, - localPath = folderName - }; - JToken tok2 = JToken.FromObject(cmd); - - // Act - dynamic jsonResult2 = controller.DeleteStoragePoolCommand(tok2); - - // Assert - dynamic ans2 = jsonResult2[0][CloudStackTypes.Answer]; - Assert.True((bool)ans2.result, (string)ans2.details); // always succeeds - } - - [Fact(Skip="these are functional tests")] - public void CreateStoragePoolCommand() - { - var cmd = new { localPath = "NULL" }; - JToken tok = JToken.FromObject(cmd); - HypervResourceController controller = new HypervResourceController(); - - // Act - dynamic jsonResult = controller.CreateStoragePoolCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.Answer]; - Assert.True((bool)ans.result, (string)ans.details); // always succeeds - } - - [Fact(Skip="these are functional tests")] - public void MaintainCommand() - { - // Omit HostEnvironment object, as this is a series of settings currently not used. - var cmd = new { }; - JToken tok = JToken.FromObject(cmd); - HypervResourceController controller = new HypervResourceController(); - - // Act - dynamic jsonResult = controller.MaintainCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.MaintainAnswer]; - Assert.True((bool)ans.result, (string)ans.details); // always succeeds - } - - [Fact(Skip="these are functional tests")] - public void SetupCommand() - { - // Omit HostEnvironment object, as this is a series of settings currently not used. - var cmd = new { multipath = false, needSetup = true }; - JToken tok = JToken.FromObject(cmd); - HypervResourceController controller = new HypervResourceController(); - - // Act - dynamic jsonResult = controller.SetupCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.SetupAnswer]; - Assert.True((bool)ans.result, (string)ans.details); // always succeeds - } - - [Fact(Skip="these are functional tests")] - public void TestPassingUserdataToVm() - { - // Sample data - String key = "cloudstack-vm-userdata"; - String value = "username=root;password=1pass@word1"; - - // Find the VM - List vmNames = wmiCallsV2.GetVmElementNames(); - - // Get associated WMI object - var vm = wmiCallsV2.GetComputerSystem(AgentSettings.Default.testKvpVmName); - - // Get existing KVP - var vmSettings = wmiCallsV2.GetVmSettings(vm); - var kvpInfo = wmiCallsV2.GetKvpSettings(vmSettings); - - // HostExchangesItems are embedded objects in the sense that the object value is stored and not a reference to the object. - string[] kvpProps = kvpInfo.HostExchangeItems; - - // If the value already exists, delete it - foreach (var item in kvpProps) - { - String wmiObjectXml = item; - String existingKey; - String existingValue; - ParseKVP(wmiObjectXml, out existingKey, out existingValue); - - if (existingKey == key) - { - wmiCallsV2.DeleteHostKvpItem(vm, existingKey); - break; - } - } - - // Add new user data - wmiCallsV2.AddUserData(vm, value); - - // Verify key added to subsystem - kvpInfo = wmiCallsV2.GetKvpSettings(vmSettings); - - // HostExchangesItems are embedded objects in the sense that the object value is stored and not a reference to the object. - kvpProps = kvpInfo.HostExchangeItems; - - // If the value already exists, delete it - bool userDataInPlace = false; - foreach (var item in kvpProps) - { - String wmiObjectXml = item; - String existingKey; - String existingValue; - ParseKVP(wmiObjectXml, out existingKey, out existingValue); - - if (existingKey == key && existingValue == value) - { -// wmiCallsV2.DeleteHostKvpItem(vm, existingKey); - userDataInPlace = true; - break; - } - } - - Assert.True(userDataInPlace, "User data key / value did no save properly"); - } - - private static void ParseKVP(String wmiObjectXml, out String existingKey, out String existingValue) - { - // Reference: http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/12/05/enumerating-parent-kvp-data.aspx - - // Create XML parser - var xmlDoc = new XmlDocument(); - - // Load WMI object - xmlDoc.LoadXml(wmiObjectXml); - - // Use xpath to get name and value - var namePropXpath = "/INSTANCE/PROPERTY[@NAME='Name']/VALUE"; - var nameNode = xmlDoc.SelectSingleNode(namePropXpath); - existingKey = nameNode.InnerText; - var dataPropXpath = "/INSTANCE/PROPERTY[@NAME='Data']/VALUE"; - var dataNode = xmlDoc.SelectSingleNode(dataPropXpath); - existingValue = dataNode.InnerText; - } - - [Fact(Skip="these are functional tests")] - public void GetVmStatsCommandFail() - { - // Use WMI to find existing VMs - List vmNames = new List(); - vmNames.Add("FakeVM"); - - var cmd = new - { - hostGuid = "FAKEguid", - hostName = AgentSettings.Default.host, - vmNames = vmNames - }; - JToken tok = JToken.FromObject(cmd); - HypervResourceController controller = new HypervResourceController(); - - // Act - dynamic jsonResult = controller.GetVmStatsCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.GetVmStatsAnswer]; - Assert.True((bool)ans.result, (string)ans.details); // always succeeds, fake VM means no answer for the named VM - } - - [Fact(Skip="these are functional tests")] - public void GetVmStatsCommand() - { - // Use WMI to find existing VMs - List vmNames = wmiCallsV2.GetVmElementNames(); - - var cmd = new - { - hostGuid = "FAKEguid", - hostName = AgentSettings.Default.host, - vmNames = vmNames - }; - JToken tok = JToken.FromObject(cmd); - HypervResourceController controller = new HypervResourceController(); - - // Act - dynamic jsonResult = controller.GetVmStatsCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.GetVmStatsAnswer]; - Assert.True((bool)ans.result, (string)ans.details); - } - - [Fact(Skip="these are functional tests")] - public void GetStorageStatsCommand() - { - // TODO: Update sample data to unsure it is using correct info. - String sample = String.Format( - #region string_literal -"{{\"" + - "id\":{0}," + - "\"localPath\":{1}," + - "\"pooltype\":\"Filesystem\"," + - "\"contextMap\":{{}}," + - "\"wait\":0}}", - JsonConvert.SerializeObject(AgentSettings.Default.testLocalStoreUUID), - JsonConvert.SerializeObject(AgentSettings.Default.testLocalStorePath) - ); - #endregion - var cmd = JsonConvert.DeserializeObject(sample); - JToken tok = JToken.FromObject(cmd); - HypervResourceController controller = new HypervResourceController(); - - // Act - dynamic jsonResult = controller.GetStorageStatsCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.GetStorageStatsAnswer]; - Assert.True((bool)ans.result, (string)ans.details); - Assert.True((long)ans.used <= (long)ans.capacity); // TODO: verify that capacity is indeed capacity and not used. - } - - // TODO: can we speed up this command? The logic takes over a second. - [Fact(Skip="these are functional tests")] - public void GetHostStatsCommand() - { - // Arrange - long hostIdVal = 5; - HypervResourceController controller = new HypervResourceController(); - string sample = string.Format( - #region string_literal -"{{" + - "\"hostGuid\":\"B4AE5970-FCBF-4780-9F8A-2D2E04FECC34-HypervResource\"," + - "\"hostName\":\"CC-SVR11\"," + - "\"hostId\":{0}," + - "\"contextMap\":{{}}," + - "\"wait\":0}}", - JsonConvert.SerializeObject(hostIdVal)); - #endregion - var cmd = JsonConvert.DeserializeObject(sample); - JToken tok = JToken.FromObject(cmd); - - // Act - dynamic jsonResult = controller.GetHostStatsCommand(tok); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.GetHostStatsAnswer]; - Assert.True((bool)ans.result); - Assert.True(hostIdVal == (long)ans.hostStats.hostId); - Assert.True(0.0 < (double)ans.hostStats.totalMemoryKBs); - Assert.True(0.0 < (double)ans.hostStats.freeMemoryKBs); - Assert.True(0.0 <= (double)ans.hostStats.networkReadKBs); - Assert.True(0.0 <= (double)ans.hostStats.networkWriteKBs); - Assert.True(0.0 <= (double)ans.hostStats.cpuUtilization); - Assert.True(100.0 >= (double)ans.hostStats.cpuUtilization); - Assert.True("host".Equals((string)ans.hostStats.entityType)); - Assert.True(String.IsNullOrEmpty((string)ans.details)); - } - - [Fact(Skip="these are functional tests")] - public void GetHostStatsCommandFail() - { - // Arrange - HypervResourceController controller = new HypervResourceController(); - var cmd = new { GetHostStatsCommand = new { hostId = "badvalueType" } }; - JToken tokFail = JToken.FromObject(cmd); - - // Act - dynamic jsonResult = controller.GetHostStatsCommand(tokFail); - - // Assert - dynamic ans = jsonResult[0][CloudStackTypes.GetHostStatsAnswer]; - Assert.False((bool)ans.result); - Assert.Null((string)ans.hostStats); - Assert.NotNull(ans.details); - } - - [Fact(Skip="these are functional tests")] - public void TestStartupCommand() - { - // Arrange - HypervResourceController controller = new HypervResourceController(); - String sampleStartupRoutingCommand = - #region string_literal - "[{\"" + CloudStackTypes.StartupRoutingCommand + "\":{" + - "\"cpus\":0," + - "\"speed\":0," + - "\"memory\":0," + - "\"dom0MinMemory\":0," + - "\"poolSync\":false," + - "\"vms\":{}," + - "\"hypervisorType\":\"Hyperv\"," + - "\"hostDetails\":{" + - "\"com.cloud.network.Networks.RouterPrivateIpStrategy\":\"HostLocal\"" + - "}," + - "\"type\":\"Routing\"," + - "\"dataCenter\":\"1\"," + - "\"pod\":\"1\"," + - "\"cluster\":\"1\"," + - "\"guid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + - "\"name\":\"localhost\"," + - "\"version\":\"4.2.0\"," + - "\"privateIpAddress\":\"1\"," + - "\"storageIpAddress\":\"1\"," + - "\"contextMap\":{}," + - "\"wait\":0}}]"; - #endregion - - uint cores; - uint mhz; - wmiCallsV2.GetProcessorResources(out cores, out mhz); - ulong memory_mb; - ulong freememory; - wmiCallsV2.GetMemoryResources(out memory_mb, out freememory); - memory_mb *= 1024; - long capacityBytes; - long availableBytes; - HypervResourceController.GetCapacityForLocalPath(wmiCallsV2.GetDefaultVirtualDiskFolder(), - out capacityBytes, out availableBytes); - var DefaultVirtualDiskFolder = JsonConvert.SerializeObject(wmiCallsV2.GetDefaultVirtualDiskFolder()); - string expected = - #region string_literal - "[{\"" + CloudStackTypes.StartupRoutingCommand + "\":{" + - "\"cpus\":" + cores + "," + - "\"speed\":" + mhz + "," + - "\"memory\":" + memory_mb + "," + - "\"dom0MinMemory\":" + (AgentSettings.Default.dom0MinMemory * 1024 * 1024) + "," + - "\"poolSync\":false," + - "\"vms\":{}," + - "\"hypervisorType\":\"Hyperv\"," + - "\"hostDetails\":{" + - "\"com.cloud.network.Networks.RouterPrivateIpStrategy\":\"HostLocal\"" + - "}," + - "\"type\":\"Routing\"," + - "\"dataCenter\":\"1\"," + - "\"pod\":\"1\"," + - "\"cluster\":\"1\"," + - "\"guid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + - "\"name\":\"localhost\"," + - "\"version\":\"4.2.0\"," + - "\"privateIpAddress\":\"" + AgentSettings.Default.private_ip_address + "\"," + - "\"storageIpAddress\":\"" + AgentSettings.Default.private_ip_address + "\"," + - "\"contextMap\":{}," + - "\"wait\":0," + - "\"privateNetmask\":\"" + AgentSettings.Default.private_ip_netmask + "\"," + - "\"privateMacAddress\":\"" + AgentSettings.Default.private_mac_address + "\"," + - "\"storageNetmask\":\"" + AgentSettings.Default.private_ip_netmask + "\"," + - "\"storageMacAddress\":\"" + AgentSettings.Default.private_mac_address + "\"," + - "\"gatewayIpAddress\":\"" + AgentSettings.Default.gateway_ip_address + "\"" + - ",\"caps\":\"hvm\"" + - "}}," + - "{\"com.cloud.agent.api.StartupStorageCommand\":{" + - "\"poolInfo\":{" + - "\"uuid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + - "\"host\":\"" + AgentSettings.Default.private_ip_address + "\"," + - "\"localPath\":" + DefaultVirtualDiskFolder + "," + - "\"hostPath\":" + DefaultVirtualDiskFolder + "," + - "\"poolType\":\"Filesystem\"," + - "\"capacityBytes\":" + capacityBytes + "," + - "\"availableBytes\":" + availableBytes + "," + - "\"details\":null" + - "}," + - "\"guid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + - "\"dataCenter\":\"1\"," + - "\"resourceType\":\"STORAGE_POOL\"" + - "}}]"; - #endregion - - dynamic jsonArray = JsonConvert.DeserializeObject(sampleStartupRoutingCommand); - - // Act - dynamic jsonResult = controller.StartupCommand(jsonArray); - - // Assert - string actual = JsonConvert.SerializeObject(jsonResult); - Assert.Equal(expected, actual); - } - - - private static string TestStartCommand() - { - // Arrange - HypervResourceController rsrcServer = new HypervResourceController(); - String sample = getSampleStartCommand(); - - - dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample); - - // Act - dynamic startAns = rsrcServer.StartCommand(jsonStartCmd); - - // Assert - Assert.NotNull(startAns[0][CloudStackTypes.StartAnswer]); - Assert.True((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details); - string vmCmdName = jsonStartCmd.vm.name.Value; - var vm = wmiCallsV2.GetComputerSystem(vmCmdName); - var vmSettings = wmiCallsV2.GetVmSettings(vm); - var memSettings = wmiCallsV2.GetMemSettings(vmSettings); - var procSettings = wmiCallsV2.GetProcSettings(vmSettings); - dynamic jsonObj = JsonConvert.DeserializeObject(sample); - var vmInfo = jsonObj.vm; - string vmName = vmInfo.name; - var nicInfo = vmInfo.nics; - int vcpus = vmInfo.cpus; - int memSize = vmInfo.maxRam / 1048576; - Assert.True((long)memSettings.VirtualQuantity == memSize); - Assert.True((long)memSettings.Reservation == memSize); - Assert.True((long)memSettings.Limit == memSize); - Assert.True((int)procSettings.VirtualQuantity == vcpus); - Assert.True((int)procSettings.Reservation == vcpus); - Assert.True((int)procSettings.Limit == 100000); - - // examine NIC for correctness - var nicSettingsViaVm = wmiCallsV2.GetEthernetPortSettings(vm); - Assert.True(nicSettingsViaVm.Length > 0, "Should be at least one ethernet port on VM"); - string expectedMac = (string)jsonStartCmd.vm.nics[0].mac; - string strippedExpectedMac = expectedMac.Replace(":", string.Empty); - Assert.Equal(nicSettingsViaVm[0].Address.ToLower(), strippedExpectedMac.ToLower()); - - // Assert switchport has correct VLAN - var ethernetConnections = wmiCallsV2.GetEthernetConnections(vm); - var vlanSettings = wmiCallsV2.GetVlanSettings(ethernetConnections[0]); - string isolationUri = (string)jsonStartCmd.vm.nics[0].isolationUri; - string vlan = isolationUri.Replace("vlan://", string.Empty); - Assert.Equal(vlanSettings.AccessVlanId.ToString(), vlan); - - return vmName; - } - - private static void TestStopCommand(string vmName) - { - // Arrange - HypervResourceController rsrcServer = new HypervResourceController(); - String sampleStop = "{\"isProxy\":false,\"vmName\":\"i-2-17-VM\",\"contextMap\":{},\"wait\":0}"; - dynamic jsonStopCmd = JsonConvert.DeserializeObject(sampleStop); - - // Act - dynamic stopAns = rsrcServer.StopCommand(jsonStopCmd); - - // Assert VM is gone! - Assert.NotNull(stopAns[0][CloudStackTypes.StopAnswer]); - Assert.True((bool)stopAns[0][CloudStackTypes.StopAnswer].result, "StopCommand did not succeed " + stopAns[0][CloudStackTypes.StopAnswer].details); - var finalVm = wmiCallsV2.GetComputerSystem(vmName); - Assert.True(wmiCallsV2.GetComputerSystem(vmName) == null); - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +using System; +using CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION; +using System.Management; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; +using System.IO; +using log4net; +using HypervResource; +using CloudStack.Plugin.AgentShell; +using System.Collections.Generic; +using System.Xml; +using Xunit; + +namespace ServerResource.Tests +{ + public class HypervResourceControllerTest + { + protected static string testCifsUrl = AgentSettings.Default.testCifsUrl; + protected static string testCifsPath = AgentSettings.Default.testCifsPath; + protected static String testPrimaryDataStoreHost = HypervResourceController.config.StorageIpAddress; + protected static String testS3TemplateName = AgentSettings.Default.testS3TemplateName; + protected static String testCifsTemplateName = AgentSettings.Default.testS3TemplateName; + protected static String testSystemVMTemplateName = AgentSettings.Default.testSystemVMTemplateName; + protected static String testSystemVMTemplateNameNoExt = AgentSettings.Default.testSystemVMTemplateNameNoExt; + protected static String testLocalStoreUUID = "5fe2bad3-d785-394e-9949-89786b8a63d2"; + protected static String testLocalStorePath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "storagepool"); + protected static String testSecondaryStoreLocalPath = Path.Combine(AgentSettings.Default.hyperv_plugin_root, "var", "test", "secondary"); + + // TODO: differentiate between NFS and HTTP template URLs. + protected static String testSampleTemplateUUID = "TestCopiedLocalTemplate.vhdx"; + protected static String testSampleTemplateURL = testSampleTemplateUUID; + + // test volumes are both a minimal size vhdx. Changing the extension to .vhd makes on corrupt. + protected static String testSampleVolumeWorkingUUID = "TestVolumeLegit.vhdx"; + protected static String testSampleVolumeCorruptUUID = "TestVolumeCorrupt.vhd"; + protected static String testSampleVolumeTempUUID = "TestVolumeTemp.vhdx"; + protected static String testSampleVolumeTempUUIDNoExt = "TestVolumeTemp"; + protected static String testSampleVolumeWorkingURIJSON; + protected static String testSampleVolumeCorruptURIJSON; + protected static String testSampleVolumeTempURIJSON; + + protected static String testSampleTemplateURLJSON; + protected static String testLocalStorePathJSON; + + protected static WmiCallsV2 wmiCallsV2 = new WmiCallsV2(); + + private static ILog s_logger = LogManager.GetLogger(typeof(HypervResourceControllerTest)); + + /// + /// Test WmiCalls to which incoming HTTP POST requests are dispatched. + /// + /// TODO: revise beyond first approximation + /// First approximation is a quick port of the existing Java tests for Hyper-V server resource. + /// A second approximation would use the AgentShell settings files directly. + /// A third approximation would look to invoke ServerResource methods via an HTTP request + /// + public HypervResourceControllerTest() + { + AgentService.ConfigServerResource(); + HypervResourceController.config.PrivateMacAddress = AgentSettings.Default.private_mac_address; + HypervResourceController.config.PrivateNetmask = AgentSettings.Default.private_ip_netmask; + HypervResourceController.config.StorageIpAddress = HypervResourceController.config.PrivateIpAddress; + HypervResourceController.config.StorageMacAddress = HypervResourceController.config.PrivateMacAddress; + HypervResourceController.config.StorageNetmask = HypervResourceController.config.PrivateNetmask; + + + // Used to create existing StoragePool in preparation for the ModifyStoragePool + testLocalStoreUUID = AgentSettings.Default.local_storage_uuid.ToString(); + + // Make sure secondary store is available. + string fullPath = Path.GetFullPath(testSecondaryStoreLocalPath); + s_logger.Info("Test secondary storage in " + fullPath); + DirectoryInfo testSecondarStoreDir = new DirectoryInfo(fullPath); + if (!testSecondarStoreDir.Exists) + { + try + { + testSecondarStoreDir.Create(); + } + catch (System.IO.IOException ex) + { + throw new NotImplementedException("Need to be able to create the folder " + testSecondarStoreDir.FullName + " failed due to " + ex.Message); + } + } + + // Convert to secondary storage string to canonical path + testSecondaryStoreLocalPath = testSecondarStoreDir.FullName; + AgentSettings.Default.local_secondary_storage_path = testSecondaryStoreLocalPath; + + // Make sure local primary storage is available + DirectoryInfo testPoolDir = new DirectoryInfo(testLocalStorePath); + Assert.True(testPoolDir.Exists, "To simulate local file system Storage Pool, you need folder at " + testPoolDir.FullName); + + // Convert to local primary storage string to canonical path + testLocalStorePath = testPoolDir.FullName; + AgentSettings.Default.local_storage_path = testLocalStorePath; + + // Clean up old test files in local storage folder + FileInfo testVolWorks = new FileInfo(Path.Combine(testLocalStorePath, testSampleVolumeWorkingUUID)); + Assert.True(testVolWorks.Exists, "Create a working virtual disk at " + testVolWorks.FullName); + + + // Delete all temporary files in local folder save the testVolWorks + foreach (var file in testPoolDir.GetFiles()) + { + if (file.FullName == testVolWorks.FullName) + { + continue; + } + file.Delete(); + file.Refresh(); + Assert.False(file.Exists, "removed file from previous test called " + file.FullName); + } + + // Recreate starting point files for test, and record JSON encoded paths for each ... + testSampleVolumeTempURIJSON = CreateTestDiskImageFromExistingImage(testVolWorks, testLocalStorePath, testSampleVolumeTempUUID); + s_logger.Info("Created " + testSampleVolumeTempURIJSON); + testSampleVolumeCorruptURIJSON = CreateTestDiskImageFromExistingImage(testVolWorks, testLocalStorePath, testSampleVolumeCorruptUUID); + s_logger.Info("Created " + testSampleVolumeCorruptURIJSON); + CreateTestDiskImageFromExistingImage(testVolWorks, testLocalStorePath, testSampleTemplateUUID); + testSampleTemplateURLJSON = JsonConvert.SerializeObject(testSampleTemplateUUID); + s_logger.Info("Created " + testSampleTemplateURLJSON + " in local storage."); + + // ... including a secondary storage template: + CreateTestDiskImageFromExistingImage(testVolWorks, testSecondarStoreDir.FullName, "af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx"); + s_logger.Info("Created " + "af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx" + " in secondary (NFS) storage."); + + + // Capture other JSON encoded paths + testSampleVolumeWorkingURIJSON = Newtonsoft.Json.JsonConvert.SerializeObject(testVolWorks.FullName); + testLocalStorePathJSON = JsonConvert.SerializeObject(testLocalStorePath); + + // TODO: may need to initialise the server resource in future. + // s_hypervresource.initialize(); + + // Verify sample template is in place storage pool + s_logger.Info("setUp complete, sample StoragePool at " + testLocalStorePathJSON + + " sample template at " + testSampleTemplateURLJSON); + } + + private String CreateTestDiskImageFromExistingImage(FileInfo srcFile, + String dstPath, + String dstFileName) + { + var newFullname = Path.Combine(dstPath, dstFileName); + var newFileInfo = new FileInfo(newFullname); + if (!newFileInfo.Exists) + { + newFileInfo = srcFile.CopyTo(newFullname); + } + newFileInfo.Refresh(); + Assert.True(newFileInfo.Exists, "Attempted to create " + newFullname + " from " + newFileInfo.FullName); + + return JsonConvert.SerializeObject(newFileInfo.FullName); + } + + [Fact(Skip="these are functional tests")] + public void TestPrimaryStorageDownloadCommandHTTP() + { + string downloadURI = "https://s3-eu-west-1.amazonaws.com/cshv3eu/SmallDisk.vhdx"; + corePrimaryStorageDownloadCommandTestCycle(downloadURI); + } + + private void corePrimaryStorageDownloadCommandTestCycle(string downloadURI) + { + // Arrange + HypervResourceController rsrcServer = new HypervResourceController(); + dynamic jsonPSDCmd = JsonConvert.DeserializeObject(samplePrimaryDownloadCommand()); + jsonPSDCmd.url = downloadURI; + + // Act + dynamic jsonResult = rsrcServer.PrimaryStorageDownloadCommand(jsonPSDCmd); + + // Assert + JObject ansAsProperty = jsonResult[0]; + dynamic ans = ansAsProperty.GetValue(CloudStackTypes.PrimaryStorageDownloadAnswer); + Assert.True((bool)ans.result, "PrimaryStorageDownloadCommand did not succeed " + ans.details); + + // Test that URL of downloaded template works for file creation. + dynamic jsonCreateCmd = JsonConvert.DeserializeObject(CreateCommandSample()); + jsonCreateCmd.templateUrl = ans.installPath; + dynamic jsonAns2 = rsrcServer.CreateCommand(jsonCreateCmd); + JObject ansAsProperty2 = jsonAns2[0]; + dynamic ans2 = ansAsProperty2.GetValue(CloudStackTypes.CreateAnswer); + + Assert.True((bool)ans2.result, (string)ans2.details); + + FileInfo newFile = new FileInfo((string)ans2.volume.path); + Assert.True(newFile.Length > 0, "The new file should have a size greater than zero"); + newFile.Delete(); + } + + private string samplePrimaryDownloadCommand() + { + String cmdJson = "{\"localPath\":" + testLocalStorePathJSON + + ",\"poolUuid\":\"" + testLocalStoreUUID + "\",\"poolId\":201," + + "\"secondaryStorageUrl\":\"nfs://10.70.176.36/mnt/cshv3/secondarystorage\"," + + "\"primaryStorageUrl\":\"nfs://" + HypervResourceController.config.StorageIpAddress + "E:\\\\Disks\\\\Disks\"," + + "\"url\":\"nfs://10.70.176.36/mnt/cshv3/secondarystorage/template/tmpl//2/204//af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx\"," + + "\"format\":\"VHDX\",\"accountId\":2,\"name\":\"204-2-5a1db1ac-932b-3e7e-a0e8-5684c72cb862\"" + + ",\"contextMap\":{},\"wait\":10800}"; + return cmdJson; + } + + public string CreateCommandSample() + { + String sample = "{\"volId\":17,\"pool\":{\"id\":201,\"uuid\":\"" + testLocalStoreUUID + "\",\"host\":\"" + HypervResourceController.config.StorageIpAddress + "\"" + + ",\"path\":" + testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"},\"diskCharacteristics\":{\"size\":0," + + "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-15\",\"useLocalStorage\":true,\"recreatable\":true,\"diskOfferingId\":11," + + "\"volumeId\":17,\"hyperType\":\"Hyperv\"},\"templateUrl\":" + testSampleTemplateURLJSON + ",\"wait\":0}"; + return sample; + } + + [Fact(Skip="these are functional tests")] + public void TestDestroyCommand() + { + // Arrange + String sampleVolume = getSampleVolumeObjectTO(); + String destroyCmd = //"{\"volume\":" + getSampleVolumeObjectTO() + "}"; + "{\"volume\":{\"name\":\"" + testSampleVolumeTempUUIDNoExt + + "\",\"storagePoolType\":\"Filesystem\"," + + "\"mountPoint\":" + + testLocalStorePathJSON + + ",\"path\":" + testSampleVolumeTempURIJSON + + ",\"storagePoolUuid\":\"" + testLocalStoreUUID + + "\"," + + "\"type\":\"ROOT\",\"id\":9,\"size\":0}}"; + + HypervResourceController rsrcServer = new HypervResourceController(); + dynamic jsonDestroyCmd = JsonConvert.DeserializeObject(destroyCmd); + + // Act + dynamic destroyAns = rsrcServer.DestroyCommand(jsonDestroyCmd); + + // Assert + JObject ansAsProperty2 = destroyAns[0]; + dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.Answer); + String path = jsonDestroyCmd.volume.path; + Assert.True((bool)ans.result, "DestroyCommand did not succeed " + ans.details); + Assert.True(!File.Exists(path), "Failed to delete file " + path); + } + + [Fact(Skip="these are functional tests")] + public void TestCreateCommand() + { + // TODO: Need sample to update the test. + // Arrange + String createCmd = "{\"volId\":10,\"pool\":{\"id\":201,\"uuid\":\"" + testLocalStoreUUID + "\",\"host\":\"" + HypervResourceController.config.StorageIpAddress + "\"" + + ",\"path\":" + testLocalStorePathJSON + ",\"port\":0,\"type\":\"Filesystem\"},\"diskCharacteristics\":{\"size\":0," + + "\"tags\":[],\"type\":\"ROOT\",\"name\":\"ROOT-9\",\"useLocalStorage\":true,\"recreatable\":true,\"diskOfferingId\":11," + + "\"volumeId\":10,\"hyperType\":\"Hyperv\"},\"templateUrl\":" + testSampleTemplateURLJSON + ",\"contextMap\":{},\"wait\":0}"; + dynamic jsonCreateCmd = JsonConvert.DeserializeObject(createCmd); + HypervResourceController rsrcServer = new HypervResourceController(); + + Assert.True(Directory.Exists(testLocalStorePath)); + string filePath = Path.Combine(testLocalStorePath, (string)JsonConvert.DeserializeObject(testSampleTemplateURLJSON)); + Assert.True(File.Exists(filePath), "The template we make volumes from is missing from path " + filePath); + int fileCount = Directory.GetFiles(testLocalStorePath).Length; + s_logger.Debug(" test local store has " + fileCount + "files"); + + // Act + // Test requires there to be a template at the tempalteUrl, which is its location in the local file system. + dynamic jsonResult = rsrcServer.CreateCommand(jsonCreateCmd); + + JObject ansAsProperty2 = jsonResult[0]; + dynamic ans = ansAsProperty2.GetValue(CloudStackTypes.CreateAnswer); + Assert.NotNull(ans); + Assert.True((bool)ans.result, "Failed to CreateCommand due to " + (string)ans.result); + Assert.Equal(Directory.GetFiles(testLocalStorePath).Length, fileCount + 1); + FileInfo newFile = new FileInfo((string)ans.volume.path); + Assert.True(newFile.Length > 0, "The new file should have a size greater than zero"); + newFile.Delete(); + } + + /// + /// Possible additional tests: place an ISO in the drive + /// + [Fact(Skip="these are functional tests")] + public void TestStartStopCommand() + { + string vmName = TestStartCommand(); + TestStopCommand(vmName); + } + + public static String getSamplePrimaryDataStoreInfo() + { + String samplePrimaryDataStoreInfo = + "{\"org.apache.cloudstack.storage.to.PrimaryDataStoreTO\":" + + "{\"uuid\":\"" + testLocalStoreUUID + "\"," + + "\"id\":201," + + "\"host\":\"" + testPrimaryDataStoreHost + "\"," + + "\"type\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO + "\"poolType\":\"Filesystem\"," + // Not used in PrimaryDataStoreTO + "\"path\":" + testLocalStorePathJSON + "," + + "\"port\":0}" + + "}"; + return samplePrimaryDataStoreInfo; + } + + public static String getSampleVolumeObjectTO() + { + String sampleVolumeObjectTO = + "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + + "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + + "\"volumeType\":\"ROOT\"," + + "\"format\":\"VHDX\"," + + "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + + "\"name\":\"" + testSampleVolumeTempUUIDNoExt + "\"," + + "\"size\":52428800," + + "\"volumeId\":10," + + // "\"vmName\":\"i-3-5-VM\"," + // TODO: do we have to fill in the vmName? + "\"accountId\":3,\"id\":10}" + + "}"; // end of destTO + return sampleVolumeObjectTO; + } + + public static String getSampleStartCommand() + { + String sample = "{\"vm\":{\"id\":17,\"name\":\"i-2-17-VM\",\"type\":\"User\",\"cpus\":1,\"speed\":500," + + "\"minRam\":536870912,\"maxRam\":536870912,\"arch\":\"x86_64\"," + + "\"os\":\"CentOS 6.0 (64-bit)\",\"bootArgs\":\"\",\"rebootOnCrash\":false," + + "\"enableHA\":false,\"limitCpuUse\":false,\"vncPassword\":\"31f82f29aff646eb\"," + + "\"params\":{},\"uuid\":\"8b030b6a-0243-440a-8cc5-45d08815ca11\"" + + ",\"disks\":[" + + "{\"data\":" + getSampleVolumeObjectTO() + ",\"diskSeq\":0,\"type\":\"ROOT\"}," + + "{\"diskSeq\":1,\"type\":\"ISO\"}" + + "]," + + "\"nics\":[" + + "{\"deviceId\":0,\"networkRateMbps\":100,\"defaultNic\":true,\"uuid\":\"99cb4813-23af-428c-a87a-2d1899be4f4b\"," + + "\"ip\":\"10.1.1.67\",\"netmask\":\"255.255.255.0\",\"gateway\":\"10.1.1.1\"," + + "\"mac\":\"02:00:51:2c:00:0e\",\"dns1\":\"4.4.4.4\",\"broadcastType\":\"Vlan\",\"type\":\"Guest\"," + + "\"broadcastUri\":\"vlan://261\",\"isolationUri\":\"vlan://261\",\"isSecurityGroupEnabled\":false}" + + "]},\"contextMap\":{},\"wait\":0}"; + return sample; + } + + + [Fact(Skip="these are functional tests")] + public void TestCopyCommandFromCifs() + { + // Arrange + string sampleCopyCommandForTemplateDownload = + #region string_literal + // org.apache.cloudstack.storage.command.CopyCommand + "{\"srcTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{\"path\":\"" + testCifsPath + "\"," + + "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + + "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + + "\"id\":206," + + "\"format\":\"VHDX\"," + + "\"accountId\":2," + + "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + + "\"hvm\":true," + + "\"displayText\":\"OS031\"," + + "\"imageDataStore\":" + + "{\"com.cloud.agent.api.to.NfsTO\":" + + "{\"_url\":\"" + testCifsUrl + "\"," + // Unique item here + "\"_role\":\"Image\"}" + + "}," + // end of imageDataStore + "\"hypervisorType\":\"Hyperv\"," + + "\"name\":\"" + testS3TemplateName + "\"}" + + "}," + // end of srcTO + "\"destTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{" + + "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + + "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + + "\"id\":206," + + "\"format\":\"VHDX\"," + + "\"accountId\":2," + + "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + + "\"hvm\":true," + + "\"displayText\":\"Test of CIFS Download\"," + + "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + // end of imageDataStore + "\"name\":\"" + testS3TemplateName + "\"," + + "\"hypervisorType\":\"Hyperv\"}" + + "}," +// end of destTO + "\"wait\":10800}"; // end of CopyCommand + #endregion + + HypervResourceController rsrcServer; + dynamic jsonDownloadCopyCmd; + string dwnldDest; + dynamic jsonCloneCopyCmd; + string newVolName; + CopyCommandTestSetupCifs(null, sampleCopyCommandForTemplateDownload, out rsrcServer, out jsonDownloadCopyCmd, out dwnldDest, out jsonCloneCopyCmd, out newVolName); + + // Act & Assert + DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); + + // Repeat to verify ability to detect existing file. + DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); + + File.Delete(dwnldDest); + } + + [Fact(Skip="these are functional tests")] + public void TestCopyCommand() + { + // Arrange + string sampleCopyCommandToCreateVolumeFromTemplate = + #region string_literal + // org.apache.cloudstack.storage.command.CopyCommand + "{\"srcTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{" + + "\"origUrl\":\"http://people.apache.org/~bhaisaab/vms/ttylinux_pv.vhd\"," + + "\"uuid\":\"9873f1c0-bdcc-11e2-8baa-ea85dab5fcd0\"," + + "\"id\":5," + + "\"format\":\"VHDX\"," + + "\"accountId\":1," + + "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + + "\"hvm\":false," + + "\"displayText\":\"tiny Linux\"," + + "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + + "\"name\":\"" + testS3TemplateName + "\"}" + + "}," + // end of srcTO + "\"destTO\":" + + "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + + "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + + "\"volumeType\":\"ROOT\"," + + "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + + "\"name\":\"ROOT-5\"," + + "\"size\":52428800," + + "\"volumeId\":10," + + "\"vmName\":\"i-3-5-VM\"," + + "\"accountId\":3," + + "\"id\":10 }" + + "}," + // end of destTO + "\"wait\":0}"; // end of Copy Command + #endregion + //"name":"ROOT-8","size":140616708,"volumeId":8,"vmName":"s-8-VM","accountId":1,"id":8}},"contextMap":{},"wait":0} + + string sampleCopyCommandForTemplateDownload = + #region string_literal + // org.apache.cloudstack.storage.command.CopyCommand + "{\"srcTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{\"path\":\"" + testS3TemplateName + ".vhdx" + "\"," + + "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + + "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + + "\"id\":206," + + "\"format\":\"VHDX\"," + + "\"accountId\":2," + + "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + + "\"hvm\":true," + + "\"displayText\":\"OS031\"," + + "\"imageDataStore\":" + + "{\"com.cloud.agent.api.to.S3TO\":" + + "{\"id\":1," + + "\"uuid\":\"95a64c8f-2128-4502-b5b4-0d7aa77406d2\"," + + "\"accessKey\":\"" + AgentSettings.Default.testS3AccessKey + "\"," + + "\"secretKey\":\"" + AgentSettings.Default.testS3SecretKey + "\"," + + "\"endPoint\":\"" + AgentSettings.Default.testS3Endpoint + "\"," + + "\"bucketName\":\"" + AgentSettings.Default.testS3Bucket + "\"," + + "\"httpsFlag\":false," + + "\"created\":\"May 19, 2013 4:17:25 PM\"}" + + "}," + // end of imageDataStore + "\"name\":\"" + testS3TemplateName + "\"}" + + "}," + // end of srcTO + "\"destTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{" + + "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + + "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + + "\"id\":206," + + "\"format\":\"VHDX\"," + + "\"accountId\":2," + + "\"checksum\":\"4b31e2846cc67fc10ea7281986519a54\"," + + "\"hvm\":true," + + "\"displayText\":\"OS031\"," + + "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + // end of imageDataStore + "\"name\":\"" + testS3TemplateName + "\"}" + + "}," +// end of destTO + "\"wait\":10800}"; // end of CopyCommand + #endregion + + HypervResourceController rsrcServer; + dynamic jsonDownloadCopyCmd; + string dwnldDest; + dynamic jsonCloneCopyCmd; + string newVolName; + CopyCommandTestSetup(sampleCopyCommandToCreateVolumeFromTemplate, sampleCopyCommandForTemplateDownload, out rsrcServer, out jsonDownloadCopyCmd, out dwnldDest, out jsonCloneCopyCmd, out newVolName); + + // Act & Assert + DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); + CreateVolumeFromTemplate(rsrcServer, jsonCloneCopyCmd, newVolName); + + // Repeat to verify ability to detect existing file. + DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); + + File.Delete(dwnldDest); + File.Delete(newVolName); + } + + private static void CreateVolumeFromTemplate(HypervResourceController rsrcServer, dynamic jsonCloneCopyCmd, string newVolName) + { + dynamic copyResult = rsrcServer.CopyCommand(jsonCloneCopyCmd); + + // Assert + Assert.NotNull(copyResult[0][CloudStackTypes.CopyCmdAnswer]); + Assert.True((bool)copyResult[0][CloudStackTypes.CopyCmdAnswer].result, "CopyCommand did not succeed " + copyResult[0][CloudStackTypes.CopyCmdAnswer].details); + Assert.True(File.Exists(newVolName), "CopyCommand failed to generate " + newVolName); + } + + private static void DownloadTemplateToPrimaryStorage(HypervResourceController rsrcServer, dynamic jsonDownloadCopyCmd, string dwnldDest) + { + dynamic dwnldResult = rsrcServer.CopyCommand(jsonDownloadCopyCmd); + + // Assert + Assert.NotNull(dwnldResult[0][CloudStackTypes.CopyCmdAnswer]); + Assert.True((bool)dwnldResult[0][CloudStackTypes.CopyCmdAnswer].result, "CopyCommand did not succeed " + dwnldResult[0][CloudStackTypes.CopyCmdAnswer].details); + Assert.True(File.Exists(dwnldDest), "CopyCommand failed to generate " + dwnldDest); + } + + [Fact(Skip="these are functional tests")] + public void TestCopyCommandBz2Img() + { + // Arrange + string sampleCopyCommandToCreateVolumeFromTemplate = + #region string_literal + // org.apache.cloudstack.storage.command.CopyCommand + "{\"srcTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{" + + "\"origUrl\":\"http://people.apache.org/~bhaisaab/vms/ttylinux_pv.vhd\"," + + "\"uuid\":\"9873f1c0-bdcc-11e2-8baa-ea85dab5fcd0\"," + + "\"id\":5," + + "\"format\":\"VHD\"," + + "\"accountId\":1," + + "\"checksum\":\"f613f38c96bf039f2e5cbf92fa8ad4f8\"," + + "\"hvm\":false," + + "\"displayText\":\"tiny Linux\"," + + "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + + "\"name\":\"" + testSystemVMTemplateNameNoExt + "\"}" + + "}," + // end of srcTO + "\"destTO\":" + + "{\"org.apache.cloudstack.storage.to.VolumeObjectTO\":" + + "{\"uuid\":\"19ae8e67-cb2c-4ab4-901e-e0b864272b59\"," + + "\"volumeType\":\"ROOT\"," + + "\"dataStore\":" + getSamplePrimaryDataStoreInfo() + "," + + "\"name\":\"ROOT-5\"," + + "\"size\":52428800," + + "\"volumeId\":10," + + "\"vmName\":\"i-3-5-VM\"," + + "\"accountId\":1," + + "\"id\":10}" + + "}," + // end of destTO + "\"wait\":0}"; // end of Copy Command + #endregion + + string sampleCopyCommandForTemplateDownload = + #region string_literal + // org.apache.cloudstack.storage.command.CopyCommand + "{\"srcTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{\"path\":\"" + testSystemVMTemplateName + "\"," + + "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + + "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + + "\"id\":206," + + "\"format\":\"VHD\"," + + "\"accountId\":1," + + "\"checksum\": \"f613f38c96bf039f2e5cbf92fa8ad4f8\"," + + "\"hvm\":true," + + "\"displayText\":\"OS031\"," + + "\"imageDataStore\":" + + "{\"com.cloud.agent.api.to.S3TO\":" + + "{\"id\":1," + + "\"uuid\":\"95a64c8f-2128-4502-b5b4-0d7aa77406d2\"," + + "\"accessKey\":\"" + AgentSettings.Default.testS3AccessKey + "\"," + + "\"secretKey\":\"" + AgentSettings.Default.testS3SecretKey + "\"," + + "\"endPoint\":\"" + AgentSettings.Default.testS3Endpoint + "\"," + + "\"bucketName\":\"" + AgentSettings.Default.testS3Bucket + "\"," + + "\"httpsFlag\":false," + + "\"created\":\"May 19, 2013 4:17:25 PM\"}" + + "}," + // end of imageDataStore + "\"name\":\"" + testSystemVMTemplateNameNoExt + "\"}" + + "}," + // end of srcTO + "\"destTO\":" + + "{\"org.apache.cloudstack.storage.to.TemplateObjectTO\":" + + "{" + + "\"origUrl\":\"http://10.147.28.7/templates/5d67394c-4efd-4b62-966b-51aa53b35277.vhd.bz2\"," + + "\"uuid\":\"7e4ca941-cb1b-4113-ab9e-043960d0fb10\"," + + "\"id\":206," + + "\"format\":\"VHD\"," + + "\"accountId\":1," + + "\"checksum\": \"f613f38c96bf039f2e5cbf92fa8ad4f8\"," + + "\"hvm\":true," + + "\"displayText\":\"OS031\"," + + "\"imageDataStore\":" + getSamplePrimaryDataStoreInfo() + "," + // end of imageDataStore + "\"name\":\"" + testSystemVMTemplateNameNoExt + "\"}" + + "}," +// end of destTO + "\"wait\":10800}"; // end of CopyCommand + #endregion + + HypervResourceController rsrcServer; + dynamic jsonDownloadCopyCmd; + string dwnldDest; + dynamic jsonCloneCopyCmd; + string newVolName; + CopyCommandTestSetup(sampleCopyCommandToCreateVolumeFromTemplate, sampleCopyCommandForTemplateDownload, out rsrcServer, out jsonDownloadCopyCmd, out dwnldDest, out jsonCloneCopyCmd, out newVolName); + + // Act & Assert + DownloadTemplateToPrimaryStorage(rsrcServer, jsonDownloadCopyCmd, dwnldDest); + CreateVolumeFromTemplate(rsrcServer, jsonCloneCopyCmd, newVolName); + + File.Delete(dwnldDest); + File.Delete(newVolName); + } + + private static void CopyCommandTestSetup(string sampleCopyCommandToCreateVolumeFromTemplate, string sampleCopyCommandForTemplateDownload, out HypervResourceController rsrcServer, out dynamic jsonDownloadCopyCmd, out string dwnldDest, out dynamic jsonCloneCopyCmd, out string newVolName) + { + rsrcServer = new HypervResourceController(); + jsonDownloadCopyCmd = JsonConvert.DeserializeObject(sampleCopyCommandForTemplateDownload); + TemplateObjectTO dwnldTemplate = TemplateObjectTO.ParseJson(jsonDownloadCopyCmd.destTO); + dwnldDest = dwnldTemplate.FullFileName; + + jsonCloneCopyCmd = JsonConvert.DeserializeObject(sampleCopyCommandToCreateVolumeFromTemplate); + VolumeObjectTO newVol = VolumeObjectTO.ParseJson(jsonCloneCopyCmd.destTO); + newVol.format = dwnldTemplate.format; + newVolName = dwnldTemplate.FullFileName; + + if (File.Exists(dwnldDest)) + { + File.Delete(dwnldDest); + } + if (File.Exists(newVolName)) + { + File.Delete(newVolName); + } + } + + private static void CopyCommandTestSetupCifs(string sampleCopyCommandToCreateVolumeFromTemplate, string sampleCopyCommandForTemplateDownload, out HypervResourceController rsrcServer, out dynamic jsonDownloadCopyCmd, out string dwnldDest, out dynamic jsonCloneCopyCmd, out string newVolName) + { + rsrcServer = new HypervResourceController(); + jsonDownloadCopyCmd = JsonConvert.DeserializeObject(sampleCopyCommandForTemplateDownload); + TemplateObjectTO dwnldTemplate = TemplateObjectTO.ParseJson(jsonDownloadCopyCmd.destTO); + dwnldDest = dwnldTemplate.FullFileName; + + if (File.Exists(dwnldDest)) + { + File.Delete(dwnldDest); + } + newVolName = null; + jsonCloneCopyCmd = null; + } + + [Fact(Skip="these are functional tests")] + public void TestModifyStoragePoolCommand() + { + // Create dummy folder + String folderName = Path.Combine(".", "Dummy"); + if (!Directory.Exists(folderName)) + { + Directory.CreateDirectory(folderName); + } + + var pool = new + { // From java class StorageFilerTO + type = Enum.GetName(typeof(StoragePoolType), StoragePoolType.Filesystem), + host = "127.0.0.1", + port = -1, + path = folderName, + uuid = Guid.NewGuid().ToString(), + userInfo = string.Empty // Used in future to hold credential + }; + + var cmd = new + { + add = true, + pool = pool, + localPath = folderName + }; + JToken tok = JToken.FromObject(cmd); + HypervResourceController controller = new HypervResourceController(); + + // Act + dynamic jsonResult = controller.ModifyStoragePoolCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.ModifyStoragePoolAnswer]; + Assert.True((bool)ans.result, (string)ans.details); // always succeeds + + // Clean up + var cmd2 = new + { + pool = pool, + localPath = folderName + }; + JToken tok2 = JToken.FromObject(cmd); + + // Act + dynamic jsonResult2 = controller.DeleteStoragePoolCommand(tok2); + + // Assert + dynamic ans2 = jsonResult2[0][CloudStackTypes.Answer]; + Assert.True((bool)ans2.result, (string)ans2.details); // always succeeds + } + + [Fact(Skip="these are functional tests")] + public void CreateStoragePoolCommand() + { + var cmd = new { localPath = "NULL" }; + JToken tok = JToken.FromObject(cmd); + HypervResourceController controller = new HypervResourceController(); + + // Act + dynamic jsonResult = controller.CreateStoragePoolCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.Answer]; + Assert.True((bool)ans.result, (string)ans.details); // always succeeds + } + + [Fact(Skip="these are functional tests")] + public void MaintainCommand() + { + // Omit HostEnvironment object, as this is a series of settings currently not used. + var cmd = new { }; + JToken tok = JToken.FromObject(cmd); + HypervResourceController controller = new HypervResourceController(); + + // Act + dynamic jsonResult = controller.MaintainCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.MaintainAnswer]; + Assert.True((bool)ans.result, (string)ans.details); // always succeeds + } + + [Fact(Skip="these are functional tests")] + public void SetupCommand() + { + // Omit HostEnvironment object, as this is a series of settings currently not used. + var cmd = new { multipath = false, needSetup = true }; + JToken tok = JToken.FromObject(cmd); + HypervResourceController controller = new HypervResourceController(); + + // Act + dynamic jsonResult = controller.SetupCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.SetupAnswer]; + Assert.True((bool)ans.result, (string)ans.details); // always succeeds + } + + [Fact(Skip="these are functional tests")] + public void TestPassingUserdataToVm() + { + // Sample data + String key = "cloudstack-vm-userdata"; + String value = "username=root;password=1pass@word1"; + + // Find the VM + List vmNames = wmiCallsV2.GetVmElementNames(); + + // Get associated WMI object + var vm = wmiCallsV2.GetComputerSystem(AgentSettings.Default.testKvpVmName); + + // Get existing KVP + var vmSettings = wmiCallsV2.GetVmSettings(vm); + var kvpInfo = wmiCallsV2.GetKvpSettings(vmSettings); + + // HostExchangesItems are embedded objects in the sense that the object value is stored and not a reference to the object. + string[] kvpProps = kvpInfo.HostExchangeItems; + + // If the value already exists, delete it + foreach (var item in kvpProps) + { + String wmiObjectXml = item; + String existingKey; + String existingValue; + ParseKVP(wmiObjectXml, out existingKey, out existingValue); + + if (existingKey == key) + { + wmiCallsV2.DeleteHostKvpItem(vm, existingKey); + break; + } + } + + // Add new user data + wmiCallsV2.AddUserData(vm, value); + + // Verify key added to subsystem + kvpInfo = wmiCallsV2.GetKvpSettings(vmSettings); + + // HostExchangesItems are embedded objects in the sense that the object value is stored and not a reference to the object. + kvpProps = kvpInfo.HostExchangeItems; + + // If the value already exists, delete it + bool userDataInPlace = false; + foreach (var item in kvpProps) + { + String wmiObjectXml = item; + String existingKey; + String existingValue; + ParseKVP(wmiObjectXml, out existingKey, out existingValue); + + if (existingKey == key && existingValue == value) + { +// wmiCallsV2.DeleteHostKvpItem(vm, existingKey); + userDataInPlace = true; + break; + } + } + + Assert.True(userDataInPlace, "User data key / value did no save properly"); + } + + private static void ParseKVP(String wmiObjectXml, out String existingKey, out String existingValue) + { + // Reference: http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/12/05/enumerating-parent-kvp-data.aspx + + // Create XML parser + var xmlDoc = new XmlDocument(); + + // Load WMI object + xmlDoc.LoadXml(wmiObjectXml); + + // Use xpath to get name and value + var namePropXpath = "/INSTANCE/PROPERTY[@NAME='Name']/VALUE"; + var nameNode = xmlDoc.SelectSingleNode(namePropXpath); + existingKey = nameNode.InnerText; + var dataPropXpath = "/INSTANCE/PROPERTY[@NAME='Data']/VALUE"; + var dataNode = xmlDoc.SelectSingleNode(dataPropXpath); + existingValue = dataNode.InnerText; + } + + [Fact(Skip="these are functional tests")] + public void GetVmStatsCommandFail() + { + // Use WMI to find existing VMs + List vmNames = new List(); + vmNames.Add("FakeVM"); + + var cmd = new + { + hostGuid = "FAKEguid", + hostName = AgentSettings.Default.host, + vmNames = vmNames + }; + JToken tok = JToken.FromObject(cmd); + HypervResourceController controller = new HypervResourceController(); + + // Act + dynamic jsonResult = controller.GetVmStatsCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.GetVmStatsAnswer]; + Assert.True((bool)ans.result, (string)ans.details); // always succeeds, fake VM means no answer for the named VM + } + + [Fact(Skip="these are functional tests")] + public void GetVmStatsCommand() + { + // Use WMI to find existing VMs + List vmNames = wmiCallsV2.GetVmElementNames(); + + var cmd = new + { + hostGuid = "FAKEguid", + hostName = AgentSettings.Default.host, + vmNames = vmNames + }; + JToken tok = JToken.FromObject(cmd); + HypervResourceController controller = new HypervResourceController(); + + // Act + dynamic jsonResult = controller.GetVmStatsCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.GetVmStatsAnswer]; + Assert.True((bool)ans.result, (string)ans.details); + } + + [Fact(Skip="these are functional tests")] + public void GetStorageStatsCommand() + { + // TODO: Update sample data to unsure it is using correct info. + String sample = String.Format( + #region string_literal +"{{\"" + + "id\":{0}," + + "\"localPath\":{1}," + + "\"pooltype\":\"Filesystem\"," + + "\"contextMap\":{{}}," + + "\"wait\":0}}", + JsonConvert.SerializeObject(AgentSettings.Default.testLocalStoreUUID), + JsonConvert.SerializeObject(AgentSettings.Default.testLocalStorePath) + ); + #endregion + var cmd = JsonConvert.DeserializeObject(sample); + JToken tok = JToken.FromObject(cmd); + HypervResourceController controller = new HypervResourceController(); + + // Act + dynamic jsonResult = controller.GetStorageStatsCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.GetStorageStatsAnswer]; + Assert.True((bool)ans.result, (string)ans.details); + Assert.True((long)ans.used <= (long)ans.capacity); // TODO: verify that capacity is indeed capacity and not used. + } + + // TODO: can we speed up this command? The logic takes over a second. + [Fact(Skip="these are functional tests")] + public void GetHostStatsCommand() + { + // Arrange + long hostIdVal = 5; + HypervResourceController controller = new HypervResourceController(); + string sample = string.Format( + #region string_literal +"{{" + + "\"hostGuid\":\"B4AE5970-FCBF-4780-9F8A-2D2E04FECC34-HypervResource\"," + + "\"hostName\":\"CC-SVR11\"," + + "\"hostId\":{0}," + + "\"contextMap\":{{}}," + + "\"wait\":0}}", + JsonConvert.SerializeObject(hostIdVal)); + #endregion + var cmd = JsonConvert.DeserializeObject(sample); + JToken tok = JToken.FromObject(cmd); + + // Act + dynamic jsonResult = controller.GetHostStatsCommand(tok); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.GetHostStatsAnswer]; + Assert.True((bool)ans.result); + Assert.True(hostIdVal == (long)ans.hostStats.hostId); + Assert.True(0.0 < (double)ans.hostStats.totalMemoryKBs); + Assert.True(0.0 < (double)ans.hostStats.freeMemoryKBs); + Assert.True(0.0 <= (double)ans.hostStats.networkReadKBs); + Assert.True(0.0 <= (double)ans.hostStats.networkWriteKBs); + Assert.True(0.0 <= (double)ans.hostStats.cpuUtilization); + Assert.True(100.0 >= (double)ans.hostStats.cpuUtilization); + Assert.True("host".Equals((string)ans.hostStats.entityType)); + Assert.True(String.IsNullOrEmpty((string)ans.details)); + } + + [Fact(Skip="these are functional tests")] + public void GetHostStatsCommandFail() + { + // Arrange + HypervResourceController controller = new HypervResourceController(); + var cmd = new { GetHostStatsCommand = new { hostId = "badvalueType" } }; + JToken tokFail = JToken.FromObject(cmd); + + // Act + dynamic jsonResult = controller.GetHostStatsCommand(tokFail); + + // Assert + dynamic ans = jsonResult[0][CloudStackTypes.GetHostStatsAnswer]; + Assert.False((bool)ans.result); + Assert.Null((string)ans.hostStats); + Assert.NotNull(ans.details); + } + + [Fact(Skip="these are functional tests")] + public void TestStartupCommand() + { + // Arrange + HypervResourceController controller = new HypervResourceController(); + String sampleStartupRoutingCommand = + #region string_literal + "[{\"" + CloudStackTypes.StartupRoutingCommand + "\":{" + + "\"cpus\":0," + + "\"speed\":0," + + "\"memory\":0," + + "\"dom0MinMemory\":0," + + "\"poolSync\":false," + + "\"vms\":{}," + + "\"hypervisorType\":\"Hyperv\"," + + "\"hostDetails\":{" + + "\"com.cloud.network.Networks.RouterPrivateIpStrategy\":\"HostLocal\"" + + "}," + + "\"type\":\"Routing\"," + + "\"dataCenter\":\"1\"," + + "\"pod\":\"1\"," + + "\"cluster\":\"1\"," + + "\"guid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + + "\"name\":\"localhost\"," + + "\"version\":\"4.2.0\"," + + "\"privateIpAddress\":\"1\"," + + "\"storageIpAddress\":\"1\"," + + "\"contextMap\":{}," + + "\"wait\":0}}]"; + #endregion + + uint cores; + uint mhz; + wmiCallsV2.GetProcessorResources(out cores, out mhz); + ulong memory_mb; + ulong freememory; + wmiCallsV2.GetMemoryResources(out memory_mb, out freememory); + memory_mb *= 1024; + long capacityBytes; + long availableBytes; + HypervResourceController.GetCapacityForLocalPath(wmiCallsV2.GetDefaultVirtualDiskFolder(), + out capacityBytes, out availableBytes); + var DefaultVirtualDiskFolder = JsonConvert.SerializeObject(wmiCallsV2.GetDefaultVirtualDiskFolder()); + string expected = + #region string_literal + "[{\"" + CloudStackTypes.StartupRoutingCommand + "\":{" + + "\"cpus\":" + cores + "," + + "\"speed\":" + mhz + "," + + "\"memory\":" + memory_mb + "," + + "\"dom0MinMemory\":" + (AgentSettings.Default.dom0MinMemory * 1024 * 1024) + "," + + "\"poolSync\":false," + + "\"vms\":{}," + + "\"hypervisorType\":\"Hyperv\"," + + "\"hostDetails\":{" + + "\"com.cloud.network.Networks.RouterPrivateIpStrategy\":\"HostLocal\"" + + "}," + + "\"type\":\"Routing\"," + + "\"dataCenter\":\"1\"," + + "\"pod\":\"1\"," + + "\"cluster\":\"1\"," + + "\"guid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + + "\"name\":\"localhost\"," + + "\"version\":\"4.2.0\"," + + "\"privateIpAddress\":\"" + AgentSettings.Default.private_ip_address + "\"," + + "\"storageIpAddress\":\"" + AgentSettings.Default.private_ip_address + "\"," + + "\"contextMap\":{}," + + "\"wait\":0," + + "\"privateNetmask\":\"" + AgentSettings.Default.private_ip_netmask + "\"," + + "\"privateMacAddress\":\"" + AgentSettings.Default.private_mac_address + "\"," + + "\"storageNetmask\":\"" + AgentSettings.Default.private_ip_netmask + "\"," + + "\"storageMacAddress\":\"" + AgentSettings.Default.private_mac_address + "\"," + + "\"gatewayIpAddress\":\"" + AgentSettings.Default.gateway_ip_address + "\"" + + ",\"caps\":\"hvm\"" + + "}}," + + "{\"com.cloud.agent.api.StartupStorageCommand\":{" + + "\"poolInfo\":{" + + "\"uuid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + + "\"host\":\"" + AgentSettings.Default.private_ip_address + "\"," + + "\"localPath\":" + DefaultVirtualDiskFolder + "," + + "\"hostPath\":" + DefaultVirtualDiskFolder + "," + + "\"poolType\":\"Filesystem\"," + + "\"capacityBytes\":" + capacityBytes + "," + + "\"availableBytes\":" + availableBytes + "," + + "\"details\":null" + + "}," + + "\"guid\":\"16f85622-4508-415e-b13a-49a39bb14e4d\"," + + "\"dataCenter\":\"1\"," + + "\"resourceType\":\"STORAGE_POOL\"" + + "}}]"; + #endregion + + dynamic jsonArray = JsonConvert.DeserializeObject(sampleStartupRoutingCommand); + + // Act + dynamic jsonResult = controller.StartupCommand(jsonArray); + + // Assert + string actual = JsonConvert.SerializeObject(jsonResult); + Assert.Equal(expected, actual); + } + + + private static string TestStartCommand() + { + // Arrange + HypervResourceController rsrcServer = new HypervResourceController(); + String sample = getSampleStartCommand(); + + + dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample); + + // Act + dynamic startAns = rsrcServer.StartCommand(jsonStartCmd); + + // Assert + Assert.NotNull(startAns[0][CloudStackTypes.StartAnswer]); + Assert.True((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details); + string vmCmdName = jsonStartCmd.vm.name.Value; + var vm = wmiCallsV2.GetComputerSystem(vmCmdName); + var vmSettings = wmiCallsV2.GetVmSettings(vm); + var memSettings = wmiCallsV2.GetMemSettings(vmSettings); + var procSettings = wmiCallsV2.GetProcSettings(vmSettings); + dynamic jsonObj = JsonConvert.DeserializeObject(sample); + var vmInfo = jsonObj.vm; + string vmName = vmInfo.name; + var nicInfo = vmInfo.nics; + int vcpus = vmInfo.cpus; + int memSize = vmInfo.maxRam / 1048576; + Assert.True((long)memSettings.VirtualQuantity == memSize); + Assert.True((long)memSettings.Reservation == memSize); + Assert.True((long)memSettings.Limit == memSize); + Assert.True((int)procSettings.VirtualQuantity == vcpus); + Assert.True((int)procSettings.Reservation == vcpus); + Assert.True((int)procSettings.Limit == 100000); + + // examine NIC for correctness + var nicSettingsViaVm = wmiCallsV2.GetEthernetPortSettings(vm); + Assert.True(nicSettingsViaVm.Length > 0, "Should be at least one ethernet port on VM"); + string expectedMac = (string)jsonStartCmd.vm.nics[0].mac; + string strippedExpectedMac = expectedMac.Replace(":", string.Empty); + Assert.Equal(nicSettingsViaVm[0].Address.ToLower(), strippedExpectedMac.ToLower()); + + // Assert switchport has correct VLAN + var ethernetConnections = wmiCallsV2.GetEthernetConnections(vm); + var vlanSettings = wmiCallsV2.GetVlanSettings(ethernetConnections[0]); + string isolationUri = (string)jsonStartCmd.vm.nics[0].isolationUri; + string vlan = isolationUri.Replace("vlan://", string.Empty); + Assert.Equal(vlanSettings.AccessVlanId.ToString(), vlan); + + return vmName; + } + + private static void TestStopCommand(string vmName) + { + // Arrange + HypervResourceController rsrcServer = new HypervResourceController(); + String sampleStop = "{\"isProxy\":false,\"vmName\":\"i-2-17-VM\",\"contextMap\":{},\"wait\":0}"; + dynamic jsonStopCmd = JsonConvert.DeserializeObject(sampleStop); + + // Act + dynamic stopAns = rsrcServer.StopCommand(jsonStopCmd); + + // Assert VM is gone! + Assert.NotNull(stopAns[0][CloudStackTypes.StopAnswer]); + Assert.True((bool)stopAns[0][CloudStackTypes.StopAnswer].result, "StopCommand did not succeed " + stopAns[0][CloudStackTypes.StopAnswer].details); + var finalVm = wmiCallsV2.GetComputerSystem(vmName); + Assert.True(wmiCallsV2.GetComputerSystem(vmName) == null); + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ComputerSystem.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ComputerSystem.cs index 530275e33588..f3f1abbcc280 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ComputerSystem.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ComputerSystem.cs @@ -1,1818 +1,1818 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_ComputerSystem - public class ComputerSystem : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_ComputerSystem"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public ComputerSystem() { - this.InitializeObject(null, null, null); - } - - public ComputerSystem(string keyCreationClassName, string keyName) { - this.InitializeObject(null, new System.Management.ManagementPath(ComputerSystem.ConstructPath(keyCreationClassName, keyName)), null); - } - - public ComputerSystem(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ComputerSystem.ConstructPath(keyCreationClassName, keyName)), null); - } - - public ComputerSystem(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public ComputerSystem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public ComputerSystem(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public ComputerSystem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public ComputerSystem(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public ComputerSystem(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] Dedicated { - get { - return ((ushort[])(curObj["Dedicated"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsFailedOverReplicationTypeNull { - get { - if ((curObj["FailedOverReplicationType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Type of failover that was performed for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public FailedOverReplicationTypeValues FailedOverReplicationType { - get { - if ((curObj["FailedOverReplicationType"] == null)) { - return ((FailedOverReplicationTypeValues)(System.Convert.ToInt32(4))); - } - return ((FailedOverReplicationTypeValues)(System.Convert.ToInt32(curObj["FailedOverReplicationType"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] IdentifyingDescriptions { - get { - return ((string[])(curObj["IdentifyingDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLastApplicationConsistentReplicationTimeNull { - get { - if ((curObj["LastApplicationConsistentReplicationTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The time at which the last application consistent replication is received on reco" + - "very for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime LastApplicationConsistentReplicationTime { - get { - if ((curObj["LastApplicationConsistentReplicationTime"] != null)) { - return ToDateTime(((string)(curObj["LastApplicationConsistentReplicationTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLastReplicationTimeNull { - get { - if ((curObj["LastReplicationTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The time at which the last replication is received on recovery for the virtual ma" + - "chine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime LastReplicationTime { - get { - if ((curObj["LastReplicationTime"] != null)) { - return ToDateTime(((string)(curObj["LastReplicationTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLastReplicationTypeNull { - get { - if ((curObj["LastReplicationType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Type of the last replication that was received for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public LastReplicationTypeValues LastReplicationType { - get { - if ((curObj["LastReplicationType"] == null)) { - return ((LastReplicationTypeValues)(System.Convert.ToInt32(4))); - } - return ((LastReplicationTypeValues)(System.Convert.ToInt32(curObj["LastReplicationType"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLastSuccessfulBackupTimeNull { - get { - if ((curObj["LastSuccessfulBackupTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The time at which the last successful backup has completed for the virtual machin" + - "e.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime LastSuccessfulBackupTime { - get { - if ((curObj["LastSuccessfulBackupTime"] != null)) { - return ToDateTime(((string)(curObj["LastSuccessfulBackupTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string NameFormat { - get { - return ((string)(curObj["NameFormat"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsNumberOfNumaNodesNull { - get { - if ((curObj["NumberOfNumaNodes"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"The number of non-uniform memory access (NUMA) nodes of the computer system. When Msvm_ComputerSystem represents the hosting computer system, this property contains the count of physical NUMA nodes. When Msvm_ComputerSystem represents a virtual computer system, this property contains the number of virtual NUMA nodes that are presented to the guest OS through the ACPI System Resource Affinity Table (SRAT).")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort NumberOfNumaNodes { - get { - if ((curObj["NumberOfNumaNodes"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["NumberOfNumaNodes"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOnTimeInMillisecondsNull { - get { - if ((curObj["OnTimeInMilliseconds"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"For the virtual system, this property describes the total up time, in milliseconds, since the machine was last turned on, reset, or restored. This time excludes the time the virtual system was in the paused state. For the host system, this property is set to NULL.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong OnTimeInMilliseconds { - get { - if ((curObj["OnTimeInMilliseconds"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["OnTimeInMilliseconds"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherDedicatedDescriptions { - get { - return ((string[])(curObj["OtherDedicatedDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherIdentifyingInfo { - get { - return ((string[])(curObj["OtherIdentifyingInfo"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] PowerManagementCapabilities { - get { - return ((ushort[])(curObj["PowerManagementCapabilities"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerContact { - get { - return ((string)(curObj["PrimaryOwnerContact"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerName { - get { - return ((string)(curObj["PrimaryOwnerName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsProcessIDNull { - get { - if ((curObj["ProcessID"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The identifier of the process under which this virtual machine is running. This v" + - "alue can be used to uniquely identify the instance of Vmwp.exe on the system tha" + - "t is running the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint ProcessID { - get { - if ((curObj["ProcessID"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["ProcessID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReplicationHealthNull { - get { - if ((curObj["ReplicationHealth"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Replication health for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ReplicationHealthValues ReplicationHealth { - get { - if ((curObj["ReplicationHealth"] == null)) { - return ((ReplicationHealthValues)(System.Convert.ToInt32(4))); - } - return ((ReplicationHealthValues)(System.Convert.ToInt32(curObj["ReplicationHealth"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReplicationModeNull { - get { - if ((curObj["ReplicationMode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Identifies replication type for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ReplicationModeValues ReplicationMode { - get { - if ((curObj["ReplicationMode"] == null)) { - return ((ReplicationModeValues)(System.Convert.ToInt32(4))); - } - return ((ReplicationModeValues)(System.Convert.ToInt32(curObj["ReplicationMode"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReplicationStateNull { - get { - if ((curObj["ReplicationState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Replication state for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ReplicationStateValues ReplicationState { - get { - if ((curObj["ReplicationState"] == null)) { - return ((ReplicationStateValues)(System.Convert.ToInt32(12))); - } - return ((ReplicationStateValues)(System.Convert.ToInt32(curObj["ReplicationState"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResetCapabilityNull { - get { - if ((curObj["ResetCapability"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResetCapability { - get { - if ((curObj["ResetCapability"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResetCapability"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Roles { - get { - return ((string[])(curObj["Roles"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastConfigurationChangeNull { - get { - if ((curObj["TimeOfLastConfigurationChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The date and time when the virtual machine configuration file was last modified. " + - "The configuration file is modified during certain virtual machine operations, as" + - " well as when any of the virtual machine or device settings are added, modified," + - " or removed.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastConfigurationChange { - get { - if ((curObj["TimeOfLastConfigurationChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastConfigurationChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeFailedOverReplicationType() { - if ((this.IsFailedOverReplicationTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLastApplicationConsistentReplicationTime() { - if ((this.IsLastApplicationConsistentReplicationTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLastReplicationTime() { - if ((this.IsLastReplicationTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLastReplicationType() { - if ((this.IsLastReplicationTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLastSuccessfulBackupTime() { - if ((this.IsLastSuccessfulBackupTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeNumberOfNumaNodes() { - if ((this.IsNumberOfNumaNodesNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOnTimeInMilliseconds() { - if ((this.IsOnTimeInMillisecondsNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeProcessID() { - if ((this.IsProcessIDNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReplicationHealth() { - if ((this.IsReplicationHealthNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReplicationMode() { - if ((this.IsReplicationModeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReplicationState() { - if ((this.IsReplicationStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResetCapability() { - if ((this.IsResetCapabilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastConfigurationChange() { - if ((this.IsTimeOfLastConfigurationChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_ComputerSystem"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static ComputerSystemCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static ComputerSystemCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static ComputerSystemCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static ComputerSystemCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_ComputerSystem"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new ComputerSystemCollection(clsObject.GetInstances(enumOptions)); - } - - public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ComputerSystem", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new ComputerSystemCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static ComputerSystem CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new ComputerSystem(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint RequestReplicationStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestReplicationStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestReplicationStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = RequestedState; - inParams["TimeoutPeriod"] = null; // ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) - { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint SetPowerState(uint PowerState, System.DateTime Time) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); - inParams["PowerState"] = ((uint)(PowerState)); - inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public enum FailedOverReplicationTypeValues { - - None = 0, - - Regular = 1, - - Application_consistent = 2, - - Planned = 3, - - NULL_ENUM_VALUE = 4, - } - - public enum LastReplicationTypeValues { - - None = 0, - - Regular = 1, - - Application_consistent = 2, - - Planned = 3, - - NULL_ENUM_VALUE = 4, - } - - public enum ReplicationHealthValues { - - Not_applicable = 0, - - Ok = 1, - - Warning = 2, - - Critical = 3, - - NULL_ENUM_VALUE = 4, - } - - public enum ReplicationModeValues { - - None = 0, - - Primary = 1, - - Recovery = 2, - - Test_Replica = 3, - - NULL_ENUM_VALUE = 4, - } - - public enum ReplicationStateValues { - - Disabled = 0, - - Ready_for_replication = 1, - - Waiting_to_complete_initial_replication = 2, - - Replicating = 3, - - Synced_replication_complete = 4, - - Recovered = 5, - - Committed = 6, - - Suspended = 7, - - Critical = 8, - - Waiting_to_start_resynchronization = 9, - - Resynchronizing = 10, - - Resynchronization_suspended = 11, - - NULL_ENUM_VALUE = 12, - } - - // Enumerator implementation for enumerating instances of the class. - public class ComputerSystemCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public ComputerSystemCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new ComputerSystem(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new ComputerSystemEnumerator(privColObj.GetEnumerator()); - } - - public class ComputerSystemEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public ComputerSystemEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new ComputerSystem(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_ComputerSystem + public class ComputerSystem : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_ComputerSystem"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public ComputerSystem() { + this.InitializeObject(null, null, null); + } + + public ComputerSystem(string keyCreationClassName, string keyName) { + this.InitializeObject(null, new System.Management.ManagementPath(ComputerSystem.ConstructPath(keyCreationClassName, keyName)), null); + } + + public ComputerSystem(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ComputerSystem.ConstructPath(keyCreationClassName, keyName)), null); + } + + public ComputerSystem(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public ComputerSystem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public ComputerSystem(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public ComputerSystem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public ComputerSystem(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public ComputerSystem(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] Dedicated { + get { + return ((ushort[])(curObj["Dedicated"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsFailedOverReplicationTypeNull { + get { + if ((curObj["FailedOverReplicationType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Type of failover that was performed for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public FailedOverReplicationTypeValues FailedOverReplicationType { + get { + if ((curObj["FailedOverReplicationType"] == null)) { + return ((FailedOverReplicationTypeValues)(System.Convert.ToInt32(4))); + } + return ((FailedOverReplicationTypeValues)(System.Convert.ToInt32(curObj["FailedOverReplicationType"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] IdentifyingDescriptions { + get { + return ((string[])(curObj["IdentifyingDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLastApplicationConsistentReplicationTimeNull { + get { + if ((curObj["LastApplicationConsistentReplicationTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The time at which the last application consistent replication is received on reco" + + "very for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime LastApplicationConsistentReplicationTime { + get { + if ((curObj["LastApplicationConsistentReplicationTime"] != null)) { + return ToDateTime(((string)(curObj["LastApplicationConsistentReplicationTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLastReplicationTimeNull { + get { + if ((curObj["LastReplicationTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The time at which the last replication is received on recovery for the virtual ma" + + "chine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime LastReplicationTime { + get { + if ((curObj["LastReplicationTime"] != null)) { + return ToDateTime(((string)(curObj["LastReplicationTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLastReplicationTypeNull { + get { + if ((curObj["LastReplicationType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Type of the last replication that was received for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public LastReplicationTypeValues LastReplicationType { + get { + if ((curObj["LastReplicationType"] == null)) { + return ((LastReplicationTypeValues)(System.Convert.ToInt32(4))); + } + return ((LastReplicationTypeValues)(System.Convert.ToInt32(curObj["LastReplicationType"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLastSuccessfulBackupTimeNull { + get { + if ((curObj["LastSuccessfulBackupTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The time at which the last successful backup has completed for the virtual machin" + + "e.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime LastSuccessfulBackupTime { + get { + if ((curObj["LastSuccessfulBackupTime"] != null)) { + return ToDateTime(((string)(curObj["LastSuccessfulBackupTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string NameFormat { + get { + return ((string)(curObj["NameFormat"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsNumberOfNumaNodesNull { + get { + if ((curObj["NumberOfNumaNodes"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"The number of non-uniform memory access (NUMA) nodes of the computer system. When Msvm_ComputerSystem represents the hosting computer system, this property contains the count of physical NUMA nodes. When Msvm_ComputerSystem represents a virtual computer system, this property contains the number of virtual NUMA nodes that are presented to the guest OS through the ACPI System Resource Affinity Table (SRAT).")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort NumberOfNumaNodes { + get { + if ((curObj["NumberOfNumaNodes"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["NumberOfNumaNodes"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOnTimeInMillisecondsNull { + get { + if ((curObj["OnTimeInMilliseconds"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"For the virtual system, this property describes the total up time, in milliseconds, since the machine was last turned on, reset, or restored. This time excludes the time the virtual system was in the paused state. For the host system, this property is set to NULL.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong OnTimeInMilliseconds { + get { + if ((curObj["OnTimeInMilliseconds"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["OnTimeInMilliseconds"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherDedicatedDescriptions { + get { + return ((string[])(curObj["OtherDedicatedDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherIdentifyingInfo { + get { + return ((string[])(curObj["OtherIdentifyingInfo"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] PowerManagementCapabilities { + get { + return ((ushort[])(curObj["PowerManagementCapabilities"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerContact { + get { + return ((string)(curObj["PrimaryOwnerContact"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerName { + get { + return ((string)(curObj["PrimaryOwnerName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsProcessIDNull { + get { + if ((curObj["ProcessID"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The identifier of the process under which this virtual machine is running. This v" + + "alue can be used to uniquely identify the instance of Vmwp.exe on the system tha" + + "t is running the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint ProcessID { + get { + if ((curObj["ProcessID"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["ProcessID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReplicationHealthNull { + get { + if ((curObj["ReplicationHealth"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Replication health for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ReplicationHealthValues ReplicationHealth { + get { + if ((curObj["ReplicationHealth"] == null)) { + return ((ReplicationHealthValues)(System.Convert.ToInt32(4))); + } + return ((ReplicationHealthValues)(System.Convert.ToInt32(curObj["ReplicationHealth"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReplicationModeNull { + get { + if ((curObj["ReplicationMode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Identifies replication type for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ReplicationModeValues ReplicationMode { + get { + if ((curObj["ReplicationMode"] == null)) { + return ((ReplicationModeValues)(System.Convert.ToInt32(4))); + } + return ((ReplicationModeValues)(System.Convert.ToInt32(curObj["ReplicationMode"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReplicationStateNull { + get { + if ((curObj["ReplicationState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Replication state for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ReplicationStateValues ReplicationState { + get { + if ((curObj["ReplicationState"] == null)) { + return ((ReplicationStateValues)(System.Convert.ToInt32(12))); + } + return ((ReplicationStateValues)(System.Convert.ToInt32(curObj["ReplicationState"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResetCapabilityNull { + get { + if ((curObj["ResetCapability"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResetCapability { + get { + if ((curObj["ResetCapability"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResetCapability"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Roles { + get { + return ((string[])(curObj["Roles"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastConfigurationChangeNull { + get { + if ((curObj["TimeOfLastConfigurationChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The date and time when the virtual machine configuration file was last modified. " + + "The configuration file is modified during certain virtual machine operations, as" + + " well as when any of the virtual machine or device settings are added, modified," + + " or removed.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastConfigurationChange { + get { + if ((curObj["TimeOfLastConfigurationChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastConfigurationChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeFailedOverReplicationType() { + if ((this.IsFailedOverReplicationTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLastApplicationConsistentReplicationTime() { + if ((this.IsLastApplicationConsistentReplicationTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLastReplicationTime() { + if ((this.IsLastReplicationTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLastReplicationType() { + if ((this.IsLastReplicationTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLastSuccessfulBackupTime() { + if ((this.IsLastSuccessfulBackupTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeNumberOfNumaNodes() { + if ((this.IsNumberOfNumaNodesNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOnTimeInMilliseconds() { + if ((this.IsOnTimeInMillisecondsNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeProcessID() { + if ((this.IsProcessIDNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReplicationHealth() { + if ((this.IsReplicationHealthNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReplicationMode() { + if ((this.IsReplicationModeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReplicationState() { + if ((this.IsReplicationStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResetCapability() { + if ((this.IsResetCapabilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastConfigurationChange() { + if ((this.IsTimeOfLastConfigurationChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_ComputerSystem"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static ComputerSystemCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static ComputerSystemCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static ComputerSystemCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static ComputerSystemCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_ComputerSystem"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new ComputerSystemCollection(clsObject.GetInstances(enumOptions)); + } + + public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static ComputerSystemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ComputerSystem", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new ComputerSystemCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static ComputerSystem CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new ComputerSystem(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint RequestReplicationStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestReplicationStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestReplicationStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = RequestedState; + inParams["TimeoutPeriod"] = null; // ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) + { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint SetPowerState(uint PowerState, System.DateTime Time) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); + inParams["PowerState"] = ((uint)(PowerState)); + inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public enum FailedOverReplicationTypeValues { + + None = 0, + + Regular = 1, + + Application_consistent = 2, + + Planned = 3, + + NULL_ENUM_VALUE = 4, + } + + public enum LastReplicationTypeValues { + + None = 0, + + Regular = 1, + + Application_consistent = 2, + + Planned = 3, + + NULL_ENUM_VALUE = 4, + } + + public enum ReplicationHealthValues { + + Not_applicable = 0, + + Ok = 1, + + Warning = 2, + + Critical = 3, + + NULL_ENUM_VALUE = 4, + } + + public enum ReplicationModeValues { + + None = 0, + + Primary = 1, + + Recovery = 2, + + Test_Replica = 3, + + NULL_ENUM_VALUE = 4, + } + + public enum ReplicationStateValues { + + Disabled = 0, + + Ready_for_replication = 1, + + Waiting_to_complete_initial_replication = 2, + + Replicating = 3, + + Synced_replication_complete = 4, + + Recovered = 5, + + Committed = 6, + + Suspended = 7, + + Critical = 8, + + Waiting_to_start_resynchronization = 9, + + Resynchronizing = 10, + + Resynchronization_suspended = 11, + + NULL_ENUM_VALUE = 12, + } + + // Enumerator implementation for enumerating instances of the class. + public class ComputerSystemCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public ComputerSystemCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new ComputerSystem(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new ComputerSystemEnumerator(privColObj.GetEnumerator()); + } + + public class ComputerSystemEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public ComputerSystemEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new ComputerSystem(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ConcreteJob.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ConcreteJob.cs index 256029d96a75..73b3599a8ce7 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ConcreteJob.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ConcreteJob.cs @@ -1,1843 +1,1843 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Time interval functions ToTimeSpan and ToDmtfTimeInterval are added to the class to convert DMTF Time Interval to System.TimeSpan and vice-versa. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_ConcreteJob - public class ConcreteJob : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_ConcreteJob"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public ConcreteJob() { - this.InitializeObject(null, null, null); - } - - public ConcreteJob(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(ConcreteJob.ConstructPath(keyInstanceID)), null); - } - - public ConcreteJob(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ConcreteJob.ConstructPath(keyInstanceID)), null); - } - - public ConcreteJob(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public ConcreteJob(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public ConcreteJob(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public ConcreteJob(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public ConcreteJob(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public ConcreteJob(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCancellableNull { - get { - if ((curObj["Cancellable"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates whether the job can be cancelled. The value of this property does not g" + - "uarantee that a request to cancel the job will succeed.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool Cancellable { - get { - if ((curObj["Cancellable"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["Cancellable"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDeleteOnCompletionNull { - get { - if ((curObj["DeleteOnCompletion"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool DeleteOnCompletion { - get { - if ((curObj["DeleteOnCompletion"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["DeleteOnCompletion"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsElapsedTimeNull { - get { - if ((curObj["ElapsedTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.TimeSpan ElapsedTime { - get { - if ((curObj["ElapsedTime"] != null)) { - return ToTimeSpan(((string)(curObj["ElapsedTime"]))); - } - else { - return new System.TimeSpan(0, 0, 0, 0, 0); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsErrorCodeNull { - get { - if ((curObj["ErrorCode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ErrorCode { - get { - if ((curObj["ErrorCode"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ErrorCode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ErrorDescription { - get { - return ((string)(curObj["ErrorDescription"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ErrorSummaryDescription { - get { - return ((string)(curObj["ErrorSummaryDescription"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsJobRunTimesNull { - get { - if ((curObj["JobRunTimes"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint JobRunTimes { - get { - if ((curObj["JobRunTimes"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["JobRunTimes"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsJobStateNull { - get { - if ((curObj["JobState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort JobState { - get { - if ((curObj["JobState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["JobState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string JobStatus { - get { - return ((string)(curObj["JobStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsJobTypeNull { - get { - if ((curObj["JobType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates the type of Job being tracked by this object.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort JobType { - get { - if ((curObj["JobType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["JobType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLocalOrUtcTimeNull { - get { - if ((curObj["LocalOrUtcTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort LocalOrUtcTime { - get { - if ((curObj["LocalOrUtcTime"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["LocalOrUtcTime"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Notify { - get { - return ((string)(curObj["Notify"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherRecoveryAction { - get { - return ((string)(curObj["OtherRecoveryAction"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Owner { - get { - return ((string)(curObj["Owner"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPercentCompleteNull { - get { - if ((curObj["PercentComplete"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PercentComplete { - get { - if ((curObj["PercentComplete"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PercentComplete"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPriorityNull { - get { - if ((curObj["Priority"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Priority { - get { - if ((curObj["Priority"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Priority"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRecoveryActionNull { - get { - if ((curObj["RecoveryAction"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RecoveryAction { - get { - if ((curObj["RecoveryAction"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RecoveryAction"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRunDayNull { - get { - if ((curObj["RunDay"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public sbyte RunDay { - get { - if ((curObj["RunDay"] == null)) { - return System.Convert.ToSByte(0); - } - return ((sbyte)(curObj["RunDay"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRunDayOfWeekNull { - get { - if ((curObj["RunDayOfWeek"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public sbyte RunDayOfWeek { - get { - if ((curObj["RunDayOfWeek"] == null)) { - return System.Convert.ToSByte(0); - } - return ((sbyte)(curObj["RunDayOfWeek"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRunMonthNull { - get { - if ((curObj["RunMonth"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public byte RunMonth { - get { - if ((curObj["RunMonth"] == null)) { - return System.Convert.ToByte(0); - } - return ((byte)(curObj["RunMonth"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRunStartIntervalNull { - get { - if ((curObj["RunStartInterval"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.TimeSpan RunStartInterval { - get { - if ((curObj["RunStartInterval"] != null)) { - return ToTimeSpan(((string)(curObj["RunStartInterval"]))); - } - else { - return new System.TimeSpan(0, 0, 0, 0, 0); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsScheduledStartTimeNull { - get { - if ((curObj["ScheduledStartTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime ScheduledStartTime { - get { - if ((curObj["ScheduledStartTime"] != null)) { - return ToDateTime(((string)(curObj["ScheduledStartTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStartTimeNull { - get { - if ((curObj["StartTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime StartTime { - get { - if ((curObj["StartTime"] != null)) { - return ToDateTime(((string)(curObj["StartTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeBeforeRemovalNull { - get { - if ((curObj["TimeBeforeRemoval"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.TimeSpan TimeBeforeRemoval { - get { - if ((curObj["TimeBeforeRemoval"] != null)) { - return ToTimeSpan(((string)(curObj["TimeBeforeRemoval"]))); - } - else { - return new System.TimeSpan(0, 0, 0, 0, 0); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeSubmittedNull { - get { - if ((curObj["TimeSubmitted"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeSubmitted { - get { - if ((curObj["TimeSubmitted"] != null)) { - return ToDateTime(((string)(curObj["TimeSubmitted"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsUntilTimeNull { - get { - if ((curObj["UntilTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime UntilTime { - get { - if ((curObj["UntilTime"] != null)) { - return ToDateTime(((string)(curObj["UntilTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeCancellable() { - if ((this.IsCancellableNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - // Converts a given time interval in DMTF format to System.TimeSpan object. - static System.TimeSpan ToTimeSpan(string dmtfTimespan) { - int days = 0; - int hours = 0; - int minutes = 0; - int seconds = 0; - long ticks = 0; - if ((dmtfTimespan == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtfTimespan.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtfTimespan.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtfTimespan.Substring(21, 4) != ":000")) { - throw new System.ArgumentOutOfRangeException(); - } - try { - string tempString = string.Empty; - tempString = dmtfTimespan.Substring(0, 8); - days = int.Parse(tempString); - tempString = dmtfTimespan.Substring(8, 2); - hours = int.Parse(tempString); - tempString = dmtfTimespan.Substring(10, 2); - minutes = int.Parse(tempString); - tempString = dmtfTimespan.Substring(12, 2); - seconds = int.Parse(tempString); - tempString = dmtfTimespan.Substring(15, 6); - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - System.TimeSpan timespan = new System.TimeSpan(days, hours, minutes, seconds, 0); - System.TimeSpan tsTemp = System.TimeSpan.FromTicks(ticks); - timespan = timespan.Add(tsTemp); - return timespan; - } - - // Converts a given System.TimeSpan object to DMTF Time interval format. - static string ToDmtfTimeInterval(System.TimeSpan timespan) { - string dmtftimespan = ((int)(timespan.Days)).ToString().PadLeft(8, '0'); - System.TimeSpan maxTimeSpan = System.TimeSpan.MaxValue; - if ((timespan.Days > maxTimeSpan.Days)) { - throw new System.ArgumentOutOfRangeException(); - } - System.TimeSpan minTimeSpan = System.TimeSpan.MinValue; - if ((timespan.Days < minTimeSpan.Days)) { - throw new System.ArgumentOutOfRangeException(); - } - dmtftimespan = string.Concat(dmtftimespan, ((int)(timespan.Hours)).ToString().PadLeft(2, '0')); - dmtftimespan = string.Concat(dmtftimespan, ((int)(timespan.Minutes)).ToString().PadLeft(2, '0')); - dmtftimespan = string.Concat(dmtftimespan, ((int)(timespan.Seconds)).ToString().PadLeft(2, '0')); - dmtftimespan = string.Concat(dmtftimespan, "."); - System.TimeSpan tsTemp = new System.TimeSpan(timespan.Days, timespan.Hours, timespan.Minutes, timespan.Seconds, 0); - long microsec = ((long)((((timespan.Ticks - tsTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicroSec = ((long)(microsec)).ToString(); - if ((strMicroSec.Length > 6)) { - strMicroSec = strMicroSec.Substring(0, 6); - } - dmtftimespan = string.Concat(dmtftimespan, strMicroSec.PadLeft(6, '0')); - dmtftimespan = string.Concat(dmtftimespan, ":000"); - return dmtftimespan; - } - - private bool ShouldSerializeDeleteOnCompletion() { - if ((this.IsDeleteOnCompletionNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeElapsedTime() { - if ((this.IsElapsedTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeErrorCode() { - if ((this.IsErrorCodeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeJobRunTimes() { - if ((this.IsJobRunTimesNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeJobState() { - if ((this.IsJobStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeJobType() { - if ((this.IsJobTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLocalOrUtcTime() { - if ((this.IsLocalOrUtcTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePercentComplete() { - if ((this.IsPercentCompleteNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePriority() { - if ((this.IsPriorityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRecoveryAction() { - if ((this.IsRecoveryActionNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRunDay() { - if ((this.IsRunDayNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRunDayOfWeek() { - if ((this.IsRunDayOfWeekNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRunMonth() { - if ((this.IsRunMonthNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRunStartInterval() { - if ((this.IsRunStartIntervalNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeScheduledStartTime() { - if ((this.IsScheduledStartTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStartTime() { - if ((this.IsStartTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeBeforeRemoval() { - if ((this.IsTimeBeforeRemovalNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeSubmitted() { - if ((this.IsTimeSubmittedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeUntilTime() { - if ((this.IsUntilTimeNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_ConcreteJob"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static ConcreteJobCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static ConcreteJobCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static ConcreteJobCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static ConcreteJobCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_ConcreteJob"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new ConcreteJobCollection(clsObject.GetInstances(enumOptions)); - } - - public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ConcreteJob", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new ConcreteJobCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static ConcreteJob CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new ConcreteJob(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint GetError(out string Error) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetError", inParams, null); - Error = System.Convert.ToString(outParams.Properties["Error"].Value); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Error = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GetErrorEx(out string[] Errors) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetErrorEx", inParams, null); - Errors = ((string[])(outParams.Properties["Errors"].Value)); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Errors = null; - return System.Convert.ToUInt32(0); - } - } - - public uint KillJob(bool DeleteOnKill) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("KillJob"); - inParams["DeleteOnKill"] = ((bool)(DeleteOnKill)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("KillJob", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.TimeSpan TimeoutPeriod) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfTimeInterval(((System.TimeSpan)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class ConcreteJobCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public ConcreteJobCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new ConcreteJob(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new ConcreteJobEnumerator(privColObj.GetEnumerator()); - } - - public class ConcreteJobEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public ConcreteJobEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new ConcreteJob(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Time interval functions ToTimeSpan and ToDmtfTimeInterval are added to the class to convert DMTF Time Interval to System.TimeSpan and vice-versa. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_ConcreteJob + public class ConcreteJob : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_ConcreteJob"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public ConcreteJob() { + this.InitializeObject(null, null, null); + } + + public ConcreteJob(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(ConcreteJob.ConstructPath(keyInstanceID)), null); + } + + public ConcreteJob(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ConcreteJob.ConstructPath(keyInstanceID)), null); + } + + public ConcreteJob(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public ConcreteJob(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public ConcreteJob(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public ConcreteJob(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public ConcreteJob(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public ConcreteJob(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCancellableNull { + get { + if ((curObj["Cancellable"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates whether the job can be cancelled. The value of this property does not g" + + "uarantee that a request to cancel the job will succeed.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool Cancellable { + get { + if ((curObj["Cancellable"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["Cancellable"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDeleteOnCompletionNull { + get { + if ((curObj["DeleteOnCompletion"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool DeleteOnCompletion { + get { + if ((curObj["DeleteOnCompletion"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["DeleteOnCompletion"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsElapsedTimeNull { + get { + if ((curObj["ElapsedTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.TimeSpan ElapsedTime { + get { + if ((curObj["ElapsedTime"] != null)) { + return ToTimeSpan(((string)(curObj["ElapsedTime"]))); + } + else { + return new System.TimeSpan(0, 0, 0, 0, 0); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsErrorCodeNull { + get { + if ((curObj["ErrorCode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ErrorCode { + get { + if ((curObj["ErrorCode"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ErrorCode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ErrorDescription { + get { + return ((string)(curObj["ErrorDescription"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ErrorSummaryDescription { + get { + return ((string)(curObj["ErrorSummaryDescription"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsJobRunTimesNull { + get { + if ((curObj["JobRunTimes"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint JobRunTimes { + get { + if ((curObj["JobRunTimes"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["JobRunTimes"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsJobStateNull { + get { + if ((curObj["JobState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort JobState { + get { + if ((curObj["JobState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["JobState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string JobStatus { + get { + return ((string)(curObj["JobStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsJobTypeNull { + get { + if ((curObj["JobType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates the type of Job being tracked by this object.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort JobType { + get { + if ((curObj["JobType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["JobType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLocalOrUtcTimeNull { + get { + if ((curObj["LocalOrUtcTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort LocalOrUtcTime { + get { + if ((curObj["LocalOrUtcTime"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["LocalOrUtcTime"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Notify { + get { + return ((string)(curObj["Notify"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherRecoveryAction { + get { + return ((string)(curObj["OtherRecoveryAction"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Owner { + get { + return ((string)(curObj["Owner"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPercentCompleteNull { + get { + if ((curObj["PercentComplete"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PercentComplete { + get { + if ((curObj["PercentComplete"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PercentComplete"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPriorityNull { + get { + if ((curObj["Priority"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Priority { + get { + if ((curObj["Priority"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Priority"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRecoveryActionNull { + get { + if ((curObj["RecoveryAction"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RecoveryAction { + get { + if ((curObj["RecoveryAction"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RecoveryAction"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRunDayNull { + get { + if ((curObj["RunDay"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public sbyte RunDay { + get { + if ((curObj["RunDay"] == null)) { + return System.Convert.ToSByte(0); + } + return ((sbyte)(curObj["RunDay"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRunDayOfWeekNull { + get { + if ((curObj["RunDayOfWeek"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public sbyte RunDayOfWeek { + get { + if ((curObj["RunDayOfWeek"] == null)) { + return System.Convert.ToSByte(0); + } + return ((sbyte)(curObj["RunDayOfWeek"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRunMonthNull { + get { + if ((curObj["RunMonth"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public byte RunMonth { + get { + if ((curObj["RunMonth"] == null)) { + return System.Convert.ToByte(0); + } + return ((byte)(curObj["RunMonth"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRunStartIntervalNull { + get { + if ((curObj["RunStartInterval"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.TimeSpan RunStartInterval { + get { + if ((curObj["RunStartInterval"] != null)) { + return ToTimeSpan(((string)(curObj["RunStartInterval"]))); + } + else { + return new System.TimeSpan(0, 0, 0, 0, 0); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsScheduledStartTimeNull { + get { + if ((curObj["ScheduledStartTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime ScheduledStartTime { + get { + if ((curObj["ScheduledStartTime"] != null)) { + return ToDateTime(((string)(curObj["ScheduledStartTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStartTimeNull { + get { + if ((curObj["StartTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime StartTime { + get { + if ((curObj["StartTime"] != null)) { + return ToDateTime(((string)(curObj["StartTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeBeforeRemovalNull { + get { + if ((curObj["TimeBeforeRemoval"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.TimeSpan TimeBeforeRemoval { + get { + if ((curObj["TimeBeforeRemoval"] != null)) { + return ToTimeSpan(((string)(curObj["TimeBeforeRemoval"]))); + } + else { + return new System.TimeSpan(0, 0, 0, 0, 0); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeSubmittedNull { + get { + if ((curObj["TimeSubmitted"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeSubmitted { + get { + if ((curObj["TimeSubmitted"] != null)) { + return ToDateTime(((string)(curObj["TimeSubmitted"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsUntilTimeNull { + get { + if ((curObj["UntilTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime UntilTime { + get { + if ((curObj["UntilTime"] != null)) { + return ToDateTime(((string)(curObj["UntilTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeCancellable() { + if ((this.IsCancellableNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + // Converts a given time interval in DMTF format to System.TimeSpan object. + static System.TimeSpan ToTimeSpan(string dmtfTimespan) { + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + long ticks = 0; + if ((dmtfTimespan == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtfTimespan.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtfTimespan.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtfTimespan.Substring(21, 4) != ":000")) { + throw new System.ArgumentOutOfRangeException(); + } + try { + string tempString = string.Empty; + tempString = dmtfTimespan.Substring(0, 8); + days = int.Parse(tempString); + tempString = dmtfTimespan.Substring(8, 2); + hours = int.Parse(tempString); + tempString = dmtfTimespan.Substring(10, 2); + minutes = int.Parse(tempString); + tempString = dmtfTimespan.Substring(12, 2); + seconds = int.Parse(tempString); + tempString = dmtfTimespan.Substring(15, 6); + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + System.TimeSpan timespan = new System.TimeSpan(days, hours, minutes, seconds, 0); + System.TimeSpan tsTemp = System.TimeSpan.FromTicks(ticks); + timespan = timespan.Add(tsTemp); + return timespan; + } + + // Converts a given System.TimeSpan object to DMTF Time interval format. + static string ToDmtfTimeInterval(System.TimeSpan timespan) { + string dmtftimespan = ((int)(timespan.Days)).ToString().PadLeft(8, '0'); + System.TimeSpan maxTimeSpan = System.TimeSpan.MaxValue; + if ((timespan.Days > maxTimeSpan.Days)) { + throw new System.ArgumentOutOfRangeException(); + } + System.TimeSpan minTimeSpan = System.TimeSpan.MinValue; + if ((timespan.Days < minTimeSpan.Days)) { + throw new System.ArgumentOutOfRangeException(); + } + dmtftimespan = string.Concat(dmtftimespan, ((int)(timespan.Hours)).ToString().PadLeft(2, '0')); + dmtftimespan = string.Concat(dmtftimespan, ((int)(timespan.Minutes)).ToString().PadLeft(2, '0')); + dmtftimespan = string.Concat(dmtftimespan, ((int)(timespan.Seconds)).ToString().PadLeft(2, '0')); + dmtftimespan = string.Concat(dmtftimespan, "."); + System.TimeSpan tsTemp = new System.TimeSpan(timespan.Days, timespan.Hours, timespan.Minutes, timespan.Seconds, 0); + long microsec = ((long)((((timespan.Ticks - tsTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicroSec = ((long)(microsec)).ToString(); + if ((strMicroSec.Length > 6)) { + strMicroSec = strMicroSec.Substring(0, 6); + } + dmtftimespan = string.Concat(dmtftimespan, strMicroSec.PadLeft(6, '0')); + dmtftimespan = string.Concat(dmtftimespan, ":000"); + return dmtftimespan; + } + + private bool ShouldSerializeDeleteOnCompletion() { + if ((this.IsDeleteOnCompletionNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeElapsedTime() { + if ((this.IsElapsedTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeErrorCode() { + if ((this.IsErrorCodeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeJobRunTimes() { + if ((this.IsJobRunTimesNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeJobState() { + if ((this.IsJobStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeJobType() { + if ((this.IsJobTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLocalOrUtcTime() { + if ((this.IsLocalOrUtcTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePercentComplete() { + if ((this.IsPercentCompleteNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePriority() { + if ((this.IsPriorityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRecoveryAction() { + if ((this.IsRecoveryActionNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRunDay() { + if ((this.IsRunDayNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRunDayOfWeek() { + if ((this.IsRunDayOfWeekNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRunMonth() { + if ((this.IsRunMonthNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRunStartInterval() { + if ((this.IsRunStartIntervalNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeScheduledStartTime() { + if ((this.IsScheduledStartTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStartTime() { + if ((this.IsStartTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeBeforeRemoval() { + if ((this.IsTimeBeforeRemovalNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeSubmitted() { + if ((this.IsTimeSubmittedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeUntilTime() { + if ((this.IsUntilTimeNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_ConcreteJob"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static ConcreteJobCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static ConcreteJobCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static ConcreteJobCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static ConcreteJobCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_ConcreteJob"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new ConcreteJobCollection(clsObject.GetInstances(enumOptions)); + } + + public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static ConcreteJobCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ConcreteJob", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new ConcreteJobCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static ConcreteJob CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new ConcreteJob(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint GetError(out string Error) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetError", inParams, null); + Error = System.Convert.ToString(outParams.Properties["Error"].Value); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Error = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GetErrorEx(out string[] Errors) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetErrorEx", inParams, null); + Errors = ((string[])(outParams.Properties["Errors"].Value)); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Errors = null; + return System.Convert.ToUInt32(0); + } + } + + public uint KillJob(bool DeleteOnKill) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("KillJob"); + inParams["DeleteOnKill"] = ((bool)(DeleteOnKill)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("KillJob", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.TimeSpan TimeoutPeriod) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfTimeInterval(((System.TimeSpan)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class ConcreteJobCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public ConcreteJobCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new ConcreteJob(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new ConcreteJobEnumerator(privColObj.GetEnumerator()); + } + + public class ConcreteJobEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public ConcreteJobEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new ConcreteJob(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetPortAllocationSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetPortAllocationSettingData.cs index 6400ec64516b..3f28309e23cb 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetPortAllocationSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetPortAllocationSettingData.cs @@ -1,1164 +1,1164 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_EthernetPortAllocationSettingData - public class EthernetPortAllocationSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_EthernetPortAllocationSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public EthernetPortAllocationSettingData() { - this.InitializeObject(null, null, null); - } - - public EthernetPortAllocationSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(EthernetPortAllocationSettingData.ConstructPath(keyInstanceID)), null); - } - - public EthernetPortAllocationSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(EthernetPortAllocationSettingData.ConstructPath(keyInstanceID)), null); - } - - public EthernetPortAllocationSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public EthernetPortAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public EthernetPortAllocationSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public EthernetPortAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public EthernetPortAllocationSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public EthernetPortAllocationSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Address { - get { - return ((string)(curObj["Address"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AddressOnParent { - get { - return ((string)(curObj["AddressOnParent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AllocationUnits { - get { - return ((string)(curObj["AllocationUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticAllocationNull { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticAllocation { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticAllocation"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticDeallocationNull { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticDeallocation { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticDeallocation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Connection { - get { - return ((string[])(curObj["Connection"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConsumerVisibilityNull { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ConsumerVisibility { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ConsumerVisibility"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDesiredVLANEndpointModeNull { - get { - if ((curObj["DesiredVLANEndpointMode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DesiredVLANEndpointMode { - get { - if ((curObj["DesiredVLANEndpointMode"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DesiredVLANEndpointMode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"EnabledState is an integer enumeration that indicates whether the allocation request is enabled or disabled. When an allocation request is marked as Disabled (3), then the allocation is not processed. The EnabledState for an active configuration is always marked as Enabled (2).")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public EnabledStateValues EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return ((EnabledStateValues)(System.Convert.ToInt32(0))); - } - return ((EnabledStateValues)(System.Convert.ToInt32(curObj["EnabledState"]))); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] HostResource { - get { - return ((string[])(curObj["HostResource"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitNull { - get { - if ((curObj["Limit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Limit { - get { - if ((curObj["Limit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Limit"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMappingBehaviorNull { - get { - if ((curObj["MappingBehavior"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort MappingBehavior { - get { - if ((curObj["MappingBehavior"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["MappingBehavior"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEndpointMode { - get { - return ((string)(curObj["OtherEndpointMode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherResourceType { - get { - return ((string)(curObj["OtherResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PoolID { - get { - return ((string)(curObj["PoolID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The list of friendly names corresponding to each entry in the RequiredFeatures.")] - public string[] RequiredFeatureHints { - get { - return ((string[])(curObj["RequiredFeatureHints"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The list of feature identifers representing all the features that are required fo" + - "r a port.")] - public string[] RequiredFeatures { - get { - return ((string[])(curObj["RequiredFeatures"])); - } - set { - curObj["RequiredFeatures"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReservationNull { - get { - if ((curObj["Reservation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Reservation { - get { - if ((curObj["Reservation"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Reservation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ResourceSubType { - get { - return ((string)(curObj["ResourceSubType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResourceTypeNull { - get { - if ((curObj["ResourceType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResourceType { - get { - if ((curObj["ResourceType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("This property specifies the network resource pool from which a connection will be" + - " allocated to test replica system when it is created.")] - public string TestReplicaPoolID { - get { - return ((string)(curObj["TestReplicaPoolID"])); - } - set { - curObj["TestReplicaPoolID"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("This property specifies the friendly name of the virtual network switch to which " + - "a connection will be allocated for the test replica system when it is created.")] - public string TestReplicaSwitchName { - get { - return ((string)(curObj["TestReplicaSwitchName"])); - } - set { - curObj["TestReplicaSwitchName"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualQuantityNull { - get { - if ((curObj["VirtualQuantity"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualQuantity { - get { - if ((curObj["VirtualQuantity"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualQuantity"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualQuantityUnits { - get { - return ((string)(curObj["VirtualQuantityUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsWeightNull { - get { - if ((curObj["Weight"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Weight { - get { - if ((curObj["Weight"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Weight"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAutomaticAllocation() { - if ((this.IsAutomaticAllocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticDeallocation() { - if ((this.IsAutomaticDeallocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConsumerVisibility() { - if ((this.IsConsumerVisibilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDesiredVLANEndpointMode() { - if ((this.IsDesiredVLANEndpointModeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimit() { - if ((this.IsLimitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMappingBehavior() { - if ((this.IsMappingBehaviorNull == false)) { - return true; - } - return false; - } - - private void ResetRequiredFeatures() { - curObj["RequiredFeatures"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeReservation() { - if ((this.IsReservationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResourceType() { - if ((this.IsResourceTypeNull == false)) { - return true; - } - return false; - } - - private void ResetTestReplicaPoolID() { - curObj["TestReplicaPoolID"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetTestReplicaSwitchName() { - curObj["TestReplicaSwitchName"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeVirtualQuantity() { - if ((this.IsVirtualQuantityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeWeight() { - if ((this.IsWeightNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_EthernetPortAllocationSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static EthernetPortAllocationSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static EthernetPortAllocationSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static EthernetPortAllocationSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static EthernetPortAllocationSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_EthernetPortAllocationSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new EthernetPortAllocationSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_EthernetPortAllocationSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new EthernetPortAllocationSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static EthernetPortAllocationSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new EthernetPortAllocationSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public enum EnabledStateValues { - - Enabled = 2, - - Disabled = 3, - - NULL_ENUM_VALUE = 0, - } - - // Enumerator implementation for enumerating instances of the class. - public class EthernetPortAllocationSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public EthernetPortAllocationSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new EthernetPortAllocationSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new EthernetPortAllocationSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class EthernetPortAllocationSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public EthernetPortAllocationSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new EthernetPortAllocationSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_EthernetPortAllocationSettingData + public class EthernetPortAllocationSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_EthernetPortAllocationSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public EthernetPortAllocationSettingData() { + this.InitializeObject(null, null, null); + } + + public EthernetPortAllocationSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(EthernetPortAllocationSettingData.ConstructPath(keyInstanceID)), null); + } + + public EthernetPortAllocationSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(EthernetPortAllocationSettingData.ConstructPath(keyInstanceID)), null); + } + + public EthernetPortAllocationSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public EthernetPortAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public EthernetPortAllocationSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public EthernetPortAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public EthernetPortAllocationSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public EthernetPortAllocationSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Address { + get { + return ((string)(curObj["Address"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AddressOnParent { + get { + return ((string)(curObj["AddressOnParent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AllocationUnits { + get { + return ((string)(curObj["AllocationUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticAllocationNull { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticAllocation { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticAllocation"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticDeallocationNull { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticDeallocation { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticDeallocation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Connection { + get { + return ((string[])(curObj["Connection"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConsumerVisibilityNull { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ConsumerVisibility { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ConsumerVisibility"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDesiredVLANEndpointModeNull { + get { + if ((curObj["DesiredVLANEndpointMode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DesiredVLANEndpointMode { + get { + if ((curObj["DesiredVLANEndpointMode"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DesiredVLANEndpointMode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"EnabledState is an integer enumeration that indicates whether the allocation request is enabled or disabled. When an allocation request is marked as Disabled (3), then the allocation is not processed. The EnabledState for an active configuration is always marked as Enabled (2).")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public EnabledStateValues EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return ((EnabledStateValues)(System.Convert.ToInt32(0))); + } + return ((EnabledStateValues)(System.Convert.ToInt32(curObj["EnabledState"]))); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] HostResource { + get { + return ((string[])(curObj["HostResource"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitNull { + get { + if ((curObj["Limit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Limit { + get { + if ((curObj["Limit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Limit"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMappingBehaviorNull { + get { + if ((curObj["MappingBehavior"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort MappingBehavior { + get { + if ((curObj["MappingBehavior"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["MappingBehavior"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEndpointMode { + get { + return ((string)(curObj["OtherEndpointMode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherResourceType { + get { + return ((string)(curObj["OtherResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PoolID { + get { + return ((string)(curObj["PoolID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The list of friendly names corresponding to each entry in the RequiredFeatures.")] + public string[] RequiredFeatureHints { + get { + return ((string[])(curObj["RequiredFeatureHints"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The list of feature identifers representing all the features that are required fo" + + "r a port.")] + public string[] RequiredFeatures { + get { + return ((string[])(curObj["RequiredFeatures"])); + } + set { + curObj["RequiredFeatures"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReservationNull { + get { + if ((curObj["Reservation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Reservation { + get { + if ((curObj["Reservation"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Reservation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ResourceSubType { + get { + return ((string)(curObj["ResourceSubType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResourceTypeNull { + get { + if ((curObj["ResourceType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResourceType { + get { + if ((curObj["ResourceType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("This property specifies the network resource pool from which a connection will be" + + " allocated to test replica system when it is created.")] + public string TestReplicaPoolID { + get { + return ((string)(curObj["TestReplicaPoolID"])); + } + set { + curObj["TestReplicaPoolID"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("This property specifies the friendly name of the virtual network switch to which " + + "a connection will be allocated for the test replica system when it is created.")] + public string TestReplicaSwitchName { + get { + return ((string)(curObj["TestReplicaSwitchName"])); + } + set { + curObj["TestReplicaSwitchName"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualQuantityNull { + get { + if ((curObj["VirtualQuantity"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualQuantity { + get { + if ((curObj["VirtualQuantity"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualQuantity"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualQuantityUnits { + get { + return ((string)(curObj["VirtualQuantityUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsWeightNull { + get { + if ((curObj["Weight"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Weight { + get { + if ((curObj["Weight"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Weight"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAutomaticAllocation() { + if ((this.IsAutomaticAllocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticDeallocation() { + if ((this.IsAutomaticDeallocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConsumerVisibility() { + if ((this.IsConsumerVisibilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDesiredVLANEndpointMode() { + if ((this.IsDesiredVLANEndpointModeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimit() { + if ((this.IsLimitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMappingBehavior() { + if ((this.IsMappingBehaviorNull == false)) { + return true; + } + return false; + } + + private void ResetRequiredFeatures() { + curObj["RequiredFeatures"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeReservation() { + if ((this.IsReservationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResourceType() { + if ((this.IsResourceTypeNull == false)) { + return true; + } + return false; + } + + private void ResetTestReplicaPoolID() { + curObj["TestReplicaPoolID"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetTestReplicaSwitchName() { + curObj["TestReplicaSwitchName"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeVirtualQuantity() { + if ((this.IsVirtualQuantityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeWeight() { + if ((this.IsWeightNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_EthernetPortAllocationSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static EthernetPortAllocationSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static EthernetPortAllocationSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static EthernetPortAllocationSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static EthernetPortAllocationSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_EthernetPortAllocationSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new EthernetPortAllocationSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static EthernetPortAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_EthernetPortAllocationSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new EthernetPortAllocationSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static EthernetPortAllocationSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new EthernetPortAllocationSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public enum EnabledStateValues { + + Enabled = 2, + + Disabled = 3, + + NULL_ENUM_VALUE = 0, + } + + // Enumerator implementation for enumerating instances of the class. + public class EthernetPortAllocationSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public EthernetPortAllocationSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new EthernetPortAllocationSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new EthernetPortAllocationSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class EthernetPortAllocationSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public EthernetPortAllocationSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new EthernetPortAllocationSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPort.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPort.cs index 018e3f5021e8..d1d2870d8e38 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPort.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPort.cs @@ -1,2119 +1,2119 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_EthernetSwitchPort - public class EthernetSwitchPort : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_EthernetSwitchPort"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public EthernetSwitchPort() { - this.InitializeObject(null, null, null); - } - - public EthernetSwitchPort(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(null, new System.Management.ManagementPath(EthernetSwitchPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); - } - - public EthernetSwitchPort(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(EthernetSwitchPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); - } - - public EthernetSwitchPort(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public EthernetSwitchPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public EthernetSwitchPort(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public EthernetSwitchPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public EthernetSwitchPort(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public EthernetSwitchPort(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsActiveMaximumTransmissionUnitNull { - get { - if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong ActiveMaximumTransmissionUnit { - get { - if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["ActiveMaximumTransmissionUnit"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AdditionalAvailability { - get { - return ((ushort[])(curObj["AdditionalAvailability"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutoSenseNull { - get { - if ((curObj["AutoSense"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutoSense { - get { - if ((curObj["AutoSense"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutoSense"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAvailabilityNull { - get { - if ((curObj["Availability"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort Availability { - get { - if ((curObj["Availability"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["Availability"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] Capabilities { - get { - return ((ushort[])(curObj["Capabilities"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] CapabilityDescriptions { - get { - return ((string[])(curObj["CapabilityDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string DeviceID { - get { - return ((string)(curObj["DeviceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] EnabledCapabilities { - get { - return ((ushort[])(curObj["EnabledCapabilities"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsErrorClearedNull { - get { - if ((curObj["ErrorCleared"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool ErrorCleared { - get { - if ((curObj["ErrorCleared"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["ErrorCleared"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ErrorDescription { - get { - return ((string)(curObj["ErrorDescription"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsFullDuplexNull { - get { - if ((curObj["FullDuplex"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool FullDuplex { - get { - if ((curObj["FullDuplex"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["FullDuplex"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] IdentifyingDescriptions { - get { - return ((string[])(curObj["IdentifyingDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsIOVOffloadUsageNull { - get { - if ((curObj["IOVOffloadUsage"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The current I/O virtualization (IOV) offload usage on this port. The usage is the" + - "amount of IOV resources in use on the port.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint IOVOffloadUsage { - get { - if ((curObj["IOVOffloadUsage"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["IOVOffloadUsage"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLastErrorCodeNull { - get { - if ((curObj["LastErrorCode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint LastErrorCode { - get { - if ((curObj["LastErrorCode"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["LastErrorCode"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLinkTechnologyNull { - get { - if ((curObj["LinkTechnology"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort LinkTechnology { - get { - if ((curObj["LinkTechnology"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["LinkTechnology"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxDataSizeNull { - get { - if ((curObj["MaxDataSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint MaxDataSize { - get { - if ((curObj["MaxDataSize"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["MaxDataSize"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxQuiesceTimeNull { - get { - if ((curObj["MaxQuiesceTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxQuiesceTime { - get { - if ((curObj["MaxQuiesceTime"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxQuiesceTime"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxSpeedNull { - get { - if ((curObj["MaxSpeed"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxSpeed { - get { - if ((curObj["MaxSpeed"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxSpeed"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] NetworkAddresses { - get { - return ((string[])(curObj["NetworkAddresses"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherEnabledCapabilities { - get { - return ((string[])(curObj["OtherEnabledCapabilities"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherIdentifyingInfo { - get { - return ((string[])(curObj["OtherIdentifyingInfo"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherLinkTechnology { - get { - return ((string)(curObj["OtherLinkTechnology"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherNetworkPortType { - get { - return ((string)(curObj["OtherNetworkPortType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherPortType { - get { - return ((string)(curObj["OtherPortType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PermanentAddress { - get { - return ((string)(curObj["PermanentAddress"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPortNumberNull { - get { - if ((curObj["PortNumber"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PortNumber { - get { - if ((curObj["PortNumber"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PortNumber"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPortTypeNull { - get { - if ((curObj["PortType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PortType { - get { - if ((curObj["PortType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PortType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] PowerManagementCapabilities { - get { - return ((ushort[])(curObj["PowerManagementCapabilities"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPowerManagementSupportedNull { - get { - if ((curObj["PowerManagementSupported"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool PowerManagementSupported { - get { - if ((curObj["PowerManagementSupported"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["PowerManagementSupported"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPowerOnHoursNull { - get { - if ((curObj["PowerOnHours"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong PowerOnHours { - get { - if ((curObj["PowerOnHours"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["PowerOnHours"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedSpeedNull { - get { - if ((curObj["RequestedSpeed"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong RequestedSpeed { - get { - if ((curObj["RequestedSpeed"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["RequestedSpeed"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSpeedNull { - get { - if ((curObj["Speed"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Speed { - get { - if ((curObj["Speed"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Speed"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStatusInfoNull { - get { - if ((curObj["StatusInfo"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort StatusInfo { - get { - if ((curObj["StatusInfo"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["StatusInfo"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSupportedMaximumTransmissionUnitNull { - get { - if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong SupportedMaximumTransmissionUnit { - get { - if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["SupportedMaximumTransmissionUnit"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemCreationClassName { - get { - return ((string)(curObj["SystemCreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemName { - get { - return ((string)(curObj["SystemName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTotalPowerOnHoursNull { - get { - if ((curObj["TotalPowerOnHours"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong TotalPowerOnHours { - get { - if ((curObj["TotalPowerOnHours"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["TotalPowerOnHours"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsUsageRestrictionNull { - get { - if ((curObj["UsageRestriction"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort UsageRestriction { - get { - if ((curObj["UsageRestriction"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["UsageRestriction"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVMQOffloadUsageNull { - get { - if ((curObj["VMQOffloadUsage"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The current VMQ offloading usage on this port. The usage is the amount of VMQ res" + - "ources in use on the port.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint VMQOffloadUsage { - get { - if ((curObj["VMQOffloadUsage"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["VMQOffloadUsage"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeActiveMaximumTransmissionUnit() { - if ((this.IsActiveMaximumTransmissionUnitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutoSense() { - if ((this.IsAutoSenseNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAvailability() { - if ((this.IsAvailabilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeErrorCleared() { - if ((this.IsErrorClearedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeFullDuplex() { - if ((this.IsFullDuplexNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeIOVOffloadUsage() { - if ((this.IsIOVOffloadUsageNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLastErrorCode() { - if ((this.IsLastErrorCodeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLinkTechnology() { - if ((this.IsLinkTechnologyNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxDataSize() { - if ((this.IsMaxDataSizeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxQuiesceTime() { - if ((this.IsMaxQuiesceTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxSpeed() { - if ((this.IsMaxSpeedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePortNumber() { - if ((this.IsPortNumberNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePortType() { - if ((this.IsPortTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePowerManagementSupported() { - if ((this.IsPowerManagementSupportedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePowerOnHours() { - if ((this.IsPowerOnHoursNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedSpeed() { - if ((this.IsRequestedSpeedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeSpeed() { - if ((this.IsSpeedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStatusInfo() { - if ((this.IsStatusInfoNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeSupportedMaximumTransmissionUnit() { - if ((this.IsSupportedMaximumTransmissionUnitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTotalPowerOnHours() { - if ((this.IsTotalPowerOnHoursNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeUsageRestriction() { - if ((this.IsUsageRestrictionNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVMQOffloadUsage() { - if ((this.IsVMQOffloadUsageNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_EthernetSwitchPort"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",DeviceID=", string.Concat("\"", string.Concat(keyDeviceID, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static EthernetSwitchPortCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static EthernetSwitchPortCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static EthernetSwitchPortCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static EthernetSwitchPortCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_EthernetSwitchPort"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new EthernetSwitchPortCollection(clsObject.GetInstances(enumOptions)); - } - - public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_EthernetSwitchPort", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new EthernetSwitchPortCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static EthernetSwitchPort CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new EthernetSwitchPort(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint EnableDevice(bool Enabled) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("EnableDevice"); - inParams["Enabled"] = ((bool)(Enabled)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnableDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint OnlineDevice(bool Online) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("OnlineDevice"); - inParams["Online"] = ((bool)(Online)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("OnlineDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint QuiesceDevice(bool Quiesce) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("QuiesceDevice"); - inParams["Quiesce"] = ((bool)(Quiesce)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("QuiesceDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint Reset() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("Reset", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RestoreProperties() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RestoreProperties", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint SaveProperties() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SaveProperties", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint SetPowerState(ushort PowerState, System.DateTime Time) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); - inParams["PowerState"] = ((ushort)(PowerState)); - inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class EthernetSwitchPortCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public EthernetSwitchPortCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new EthernetSwitchPort(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new EthernetSwitchPortEnumerator(privColObj.GetEnumerator()); - } - - public class EthernetSwitchPortEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public EthernetSwitchPortEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new EthernetSwitchPort(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_EthernetSwitchPort + public class EthernetSwitchPort : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_EthernetSwitchPort"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public EthernetSwitchPort() { + this.InitializeObject(null, null, null); + } + + public EthernetSwitchPort(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(null, new System.Management.ManagementPath(EthernetSwitchPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); + } + + public EthernetSwitchPort(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(EthernetSwitchPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); + } + + public EthernetSwitchPort(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public EthernetSwitchPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public EthernetSwitchPort(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public EthernetSwitchPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public EthernetSwitchPort(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public EthernetSwitchPort(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsActiveMaximumTransmissionUnitNull { + get { + if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong ActiveMaximumTransmissionUnit { + get { + if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["ActiveMaximumTransmissionUnit"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AdditionalAvailability { + get { + return ((ushort[])(curObj["AdditionalAvailability"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutoSenseNull { + get { + if ((curObj["AutoSense"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutoSense { + get { + if ((curObj["AutoSense"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutoSense"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAvailabilityNull { + get { + if ((curObj["Availability"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort Availability { + get { + if ((curObj["Availability"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["Availability"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] Capabilities { + get { + return ((ushort[])(curObj["Capabilities"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] CapabilityDescriptions { + get { + return ((string[])(curObj["CapabilityDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string DeviceID { + get { + return ((string)(curObj["DeviceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] EnabledCapabilities { + get { + return ((ushort[])(curObj["EnabledCapabilities"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsErrorClearedNull { + get { + if ((curObj["ErrorCleared"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool ErrorCleared { + get { + if ((curObj["ErrorCleared"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["ErrorCleared"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ErrorDescription { + get { + return ((string)(curObj["ErrorDescription"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsFullDuplexNull { + get { + if ((curObj["FullDuplex"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool FullDuplex { + get { + if ((curObj["FullDuplex"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["FullDuplex"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] IdentifyingDescriptions { + get { + return ((string[])(curObj["IdentifyingDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsIOVOffloadUsageNull { + get { + if ((curObj["IOVOffloadUsage"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The current I/O virtualization (IOV) offload usage on this port. The usage is the" + + "amount of IOV resources in use on the port.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint IOVOffloadUsage { + get { + if ((curObj["IOVOffloadUsage"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["IOVOffloadUsage"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLastErrorCodeNull { + get { + if ((curObj["LastErrorCode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint LastErrorCode { + get { + if ((curObj["LastErrorCode"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["LastErrorCode"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLinkTechnologyNull { + get { + if ((curObj["LinkTechnology"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort LinkTechnology { + get { + if ((curObj["LinkTechnology"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["LinkTechnology"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxDataSizeNull { + get { + if ((curObj["MaxDataSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint MaxDataSize { + get { + if ((curObj["MaxDataSize"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["MaxDataSize"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxQuiesceTimeNull { + get { + if ((curObj["MaxQuiesceTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxQuiesceTime { + get { + if ((curObj["MaxQuiesceTime"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxQuiesceTime"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxSpeedNull { + get { + if ((curObj["MaxSpeed"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxSpeed { + get { + if ((curObj["MaxSpeed"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxSpeed"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] NetworkAddresses { + get { + return ((string[])(curObj["NetworkAddresses"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherEnabledCapabilities { + get { + return ((string[])(curObj["OtherEnabledCapabilities"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherIdentifyingInfo { + get { + return ((string[])(curObj["OtherIdentifyingInfo"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherLinkTechnology { + get { + return ((string)(curObj["OtherLinkTechnology"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherNetworkPortType { + get { + return ((string)(curObj["OtherNetworkPortType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherPortType { + get { + return ((string)(curObj["OtherPortType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PermanentAddress { + get { + return ((string)(curObj["PermanentAddress"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPortNumberNull { + get { + if ((curObj["PortNumber"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PortNumber { + get { + if ((curObj["PortNumber"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PortNumber"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPortTypeNull { + get { + if ((curObj["PortType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PortType { + get { + if ((curObj["PortType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PortType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] PowerManagementCapabilities { + get { + return ((ushort[])(curObj["PowerManagementCapabilities"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPowerManagementSupportedNull { + get { + if ((curObj["PowerManagementSupported"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool PowerManagementSupported { + get { + if ((curObj["PowerManagementSupported"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["PowerManagementSupported"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPowerOnHoursNull { + get { + if ((curObj["PowerOnHours"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong PowerOnHours { + get { + if ((curObj["PowerOnHours"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["PowerOnHours"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedSpeedNull { + get { + if ((curObj["RequestedSpeed"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong RequestedSpeed { + get { + if ((curObj["RequestedSpeed"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["RequestedSpeed"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSpeedNull { + get { + if ((curObj["Speed"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Speed { + get { + if ((curObj["Speed"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Speed"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStatusInfoNull { + get { + if ((curObj["StatusInfo"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort StatusInfo { + get { + if ((curObj["StatusInfo"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["StatusInfo"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSupportedMaximumTransmissionUnitNull { + get { + if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong SupportedMaximumTransmissionUnit { + get { + if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["SupportedMaximumTransmissionUnit"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemCreationClassName { + get { + return ((string)(curObj["SystemCreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemName { + get { + return ((string)(curObj["SystemName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTotalPowerOnHoursNull { + get { + if ((curObj["TotalPowerOnHours"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong TotalPowerOnHours { + get { + if ((curObj["TotalPowerOnHours"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["TotalPowerOnHours"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsUsageRestrictionNull { + get { + if ((curObj["UsageRestriction"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort UsageRestriction { + get { + if ((curObj["UsageRestriction"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["UsageRestriction"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVMQOffloadUsageNull { + get { + if ((curObj["VMQOffloadUsage"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The current VMQ offloading usage on this port. The usage is the amount of VMQ res" + + "ources in use on the port.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint VMQOffloadUsage { + get { + if ((curObj["VMQOffloadUsage"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["VMQOffloadUsage"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeActiveMaximumTransmissionUnit() { + if ((this.IsActiveMaximumTransmissionUnitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutoSense() { + if ((this.IsAutoSenseNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAvailability() { + if ((this.IsAvailabilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeErrorCleared() { + if ((this.IsErrorClearedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeFullDuplex() { + if ((this.IsFullDuplexNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeIOVOffloadUsage() { + if ((this.IsIOVOffloadUsageNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLastErrorCode() { + if ((this.IsLastErrorCodeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLinkTechnology() { + if ((this.IsLinkTechnologyNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxDataSize() { + if ((this.IsMaxDataSizeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxQuiesceTime() { + if ((this.IsMaxQuiesceTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxSpeed() { + if ((this.IsMaxSpeedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePortNumber() { + if ((this.IsPortNumberNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePortType() { + if ((this.IsPortTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePowerManagementSupported() { + if ((this.IsPowerManagementSupportedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePowerOnHours() { + if ((this.IsPowerOnHoursNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedSpeed() { + if ((this.IsRequestedSpeedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeSpeed() { + if ((this.IsSpeedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStatusInfo() { + if ((this.IsStatusInfoNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeSupportedMaximumTransmissionUnit() { + if ((this.IsSupportedMaximumTransmissionUnitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTotalPowerOnHours() { + if ((this.IsTotalPowerOnHoursNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeUsageRestriction() { + if ((this.IsUsageRestrictionNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVMQOffloadUsage() { + if ((this.IsVMQOffloadUsageNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_EthernetSwitchPort"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",DeviceID=", string.Concat("\"", string.Concat(keyDeviceID, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static EthernetSwitchPortCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static EthernetSwitchPortCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static EthernetSwitchPortCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static EthernetSwitchPortCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_EthernetSwitchPort"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new EthernetSwitchPortCollection(clsObject.GetInstances(enumOptions)); + } + + public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static EthernetSwitchPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_EthernetSwitchPort", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new EthernetSwitchPortCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static EthernetSwitchPort CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new EthernetSwitchPort(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint EnableDevice(bool Enabled) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("EnableDevice"); + inParams["Enabled"] = ((bool)(Enabled)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnableDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint OnlineDevice(bool Online) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("OnlineDevice"); + inParams["Online"] = ((bool)(Online)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("OnlineDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint QuiesceDevice(bool Quiesce) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("QuiesceDevice"); + inParams["Quiesce"] = ((bool)(Quiesce)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("QuiesceDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint Reset() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("Reset", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RestoreProperties() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RestoreProperties", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint SaveProperties() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SaveProperties", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint SetPowerState(ushort PowerState, System.DateTime Time) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); + inParams["PowerState"] = ((ushort)(PowerState)); + inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class EthernetSwitchPortCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public EthernetSwitchPortCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new EthernetSwitchPort(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new EthernetSwitchPortEnumerator(privColObj.GetEnumerator()); + } + + public class EthernetSwitchPortEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public EthernetSwitchPortEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new EthernetSwitchPort(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPortVlanSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPortVlanSettingData.cs index 5418bec7f98b..24cc7dbf41eb 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPortVlanSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_EthernetSwitchPortVlanSettingData.cs @@ -1,1022 +1,1022 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_EthernetSwitchPortVlanSettingData - public class EthernetSwitchPortVlanSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_EthernetSwitchPortVlanSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public EthernetSwitchPortVlanSettingData() { - this.InitializeObject(null, null, null); - } - - public EthernetSwitchPortVlanSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(EthernetSwitchPortVlanSettingData.ConstructPath(keyInstanceID)), null); - } - - public EthernetSwitchPortVlanSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(EthernetSwitchPortVlanSettingData.ConstructPath(keyInstanceID)), null); - } - - public EthernetSwitchPortVlanSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public EthernetSwitchPortVlanSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public EthernetSwitchPortVlanSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public EthernetSwitchPortVlanSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public EthernetSwitchPortVlanSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public EthernetSwitchPortVlanSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAccessVlanIdNull { - get { - if ((curObj["AccessVlanId"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The vlan ID in access mode.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort AccessVlanId { - get { - if ((curObj["AccessVlanId"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["AccessVlanId"])); - } - set { - curObj["AccessVlanId"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsNativeVlanIdNull { - get { - if ((curObj["NativeVlanId"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The vlan ID in trunk mode.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort NativeVlanId { - get { - if ((curObj["NativeVlanId"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["NativeVlanId"])); - } - set { - curObj["NativeVlanId"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperationModeNull { - get { - if ((curObj["OperationMode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The vlan operation modes.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public OperationModeValues OperationMode { - get { - if ((curObj["OperationMode"] == null)) { - return ((OperationModeValues)(System.Convert.ToInt32(0))); - } - return ((OperationModeValues)(System.Convert.ToInt32(curObj["OperationMode"]))); - } - set { - if ((OperationModeValues.NULL_ENUM_VALUE == value)) { - curObj["OperationMode"] = null; - } - else { - curObj["OperationMode"] = value; - } - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryVlanIdNull { - get { - if ((curObj["PrimaryVlanId"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The primary vlan ID in private mode.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryVlanId { - get { - if ((curObj["PrimaryVlanId"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryVlanId"])); - } - set { - curObj["PrimaryVlanId"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The prune vlan ID bitmap in trunk mode.")] - public ushort[] PruneVlanIdArray { - get { - return ((ushort[])(curObj["PruneVlanIdArray"])); - } - set { - curObj["PruneVlanIdArray"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPvlanModeNull { - get { - if ((curObj["PvlanMode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The private vlan modes.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public PvlanModeValues PvlanMode { - get { - if ((curObj["PvlanMode"] == null)) { - return ((PvlanModeValues)(System.Convert.ToInt32(0))); - } - return ((PvlanModeValues)(System.Convert.ToInt32(curObj["PvlanMode"]))); - } - set { - if ((PvlanModeValues.NULL_ENUM_VALUE == value)) { - curObj["PvlanMode"] = null; - } - else { - curObj["PvlanMode"] = value; - } - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSecondaryVlanIdNull { - get { - if ((curObj["SecondaryVlanId"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The secondary vlan ID in private mode.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort SecondaryVlanId { - get { - if ((curObj["SecondaryVlanId"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["SecondaryVlanId"])); - } - set { - curObj["SecondaryVlanId"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The secondary vlan ID bitmap in private mode.")] - public ushort[] SecondaryVlanIdArray { - get { - return ((ushort[])(curObj["SecondaryVlanIdArray"])); - } - set { - curObj["SecondaryVlanIdArray"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The trunk vlan ID bitmap in trunk mode.")] - public ushort[] TrunkVlanIdArray { - get { - return ((ushort[])(curObj["TrunkVlanIdArray"])); - } - set { - curObj["TrunkVlanIdArray"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAccessVlanId() { - if ((this.IsAccessVlanIdNull == false)) { - return true; - } - return false; - } - - private void ResetAccessVlanId() { - curObj["AccessVlanId"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeNativeVlanId() { - if ((this.IsNativeVlanIdNull == false)) { - return true; - } - return false; - } - - private void ResetNativeVlanId() { - curObj["NativeVlanId"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeOperationMode() { - if ((this.IsOperationModeNull == false)) { - return true; - } - return false; - } - - private void ResetOperationMode() { - curObj["OperationMode"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializePrimaryVlanId() { - if ((this.IsPrimaryVlanIdNull == false)) { - return true; - } - return false; - } - - private void ResetPrimaryVlanId() { - curObj["PrimaryVlanId"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetPruneVlanIdArray() { - curObj["PruneVlanIdArray"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializePvlanMode() { - if ((this.IsPvlanModeNull == false)) { - return true; - } - return false; - } - - private void ResetPvlanMode() { - curObj["PvlanMode"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeSecondaryVlanId() { - if ((this.IsSecondaryVlanIdNull == false)) { - return true; - } - return false; - } - - private void ResetSecondaryVlanId() { - curObj["SecondaryVlanId"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetSecondaryVlanIdArray() { - curObj["SecondaryVlanIdArray"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetTrunkVlanIdArray() { - curObj["TrunkVlanIdArray"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_EthernetSwitchPortVlanSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static EthernetSwitchPortVlanSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static EthernetSwitchPortVlanSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static EthernetSwitchPortVlanSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static EthernetSwitchPortVlanSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_EthernetSwitchPortVlanSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new EthernetSwitchPortVlanSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_EthernetSwitchPortVlanSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new EthernetSwitchPortVlanSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static EthernetSwitchPortVlanSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new EthernetSwitchPortVlanSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public enum OperationModeValues { - - Access = 1, - - Trunk = 2, - - Private = 3, - - NULL_ENUM_VALUE = 0, - } - - public enum PvlanModeValues { - - Isolated = 1, - - Community = 2, - - Promiscuous = 3, - - NULL_ENUM_VALUE = 0, - } - - // Enumerator implementation for enumerating instances of the class. - public class EthernetSwitchPortVlanSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public EthernetSwitchPortVlanSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new EthernetSwitchPortVlanSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new EthernetSwitchPortVlanSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class EthernetSwitchPortVlanSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public EthernetSwitchPortVlanSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new EthernetSwitchPortVlanSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_EthernetSwitchPortVlanSettingData + public class EthernetSwitchPortVlanSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_EthernetSwitchPortVlanSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public EthernetSwitchPortVlanSettingData() { + this.InitializeObject(null, null, null); + } + + public EthernetSwitchPortVlanSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(EthernetSwitchPortVlanSettingData.ConstructPath(keyInstanceID)), null); + } + + public EthernetSwitchPortVlanSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(EthernetSwitchPortVlanSettingData.ConstructPath(keyInstanceID)), null); + } + + public EthernetSwitchPortVlanSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public EthernetSwitchPortVlanSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public EthernetSwitchPortVlanSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public EthernetSwitchPortVlanSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public EthernetSwitchPortVlanSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public EthernetSwitchPortVlanSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAccessVlanIdNull { + get { + if ((curObj["AccessVlanId"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The vlan ID in access mode.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort AccessVlanId { + get { + if ((curObj["AccessVlanId"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["AccessVlanId"])); + } + set { + curObj["AccessVlanId"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsNativeVlanIdNull { + get { + if ((curObj["NativeVlanId"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The vlan ID in trunk mode.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort NativeVlanId { + get { + if ((curObj["NativeVlanId"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["NativeVlanId"])); + } + set { + curObj["NativeVlanId"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperationModeNull { + get { + if ((curObj["OperationMode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The vlan operation modes.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public OperationModeValues OperationMode { + get { + if ((curObj["OperationMode"] == null)) { + return ((OperationModeValues)(System.Convert.ToInt32(0))); + } + return ((OperationModeValues)(System.Convert.ToInt32(curObj["OperationMode"]))); + } + set { + if ((OperationModeValues.NULL_ENUM_VALUE == value)) { + curObj["OperationMode"] = null; + } + else { + curObj["OperationMode"] = value; + } + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryVlanIdNull { + get { + if ((curObj["PrimaryVlanId"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The primary vlan ID in private mode.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryVlanId { + get { + if ((curObj["PrimaryVlanId"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryVlanId"])); + } + set { + curObj["PrimaryVlanId"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The prune vlan ID bitmap in trunk mode.")] + public ushort[] PruneVlanIdArray { + get { + return ((ushort[])(curObj["PruneVlanIdArray"])); + } + set { + curObj["PruneVlanIdArray"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPvlanModeNull { + get { + if ((curObj["PvlanMode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The private vlan modes.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public PvlanModeValues PvlanMode { + get { + if ((curObj["PvlanMode"] == null)) { + return ((PvlanModeValues)(System.Convert.ToInt32(0))); + } + return ((PvlanModeValues)(System.Convert.ToInt32(curObj["PvlanMode"]))); + } + set { + if ((PvlanModeValues.NULL_ENUM_VALUE == value)) { + curObj["PvlanMode"] = null; + } + else { + curObj["PvlanMode"] = value; + } + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSecondaryVlanIdNull { + get { + if ((curObj["SecondaryVlanId"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The secondary vlan ID in private mode.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort SecondaryVlanId { + get { + if ((curObj["SecondaryVlanId"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["SecondaryVlanId"])); + } + set { + curObj["SecondaryVlanId"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The secondary vlan ID bitmap in private mode.")] + public ushort[] SecondaryVlanIdArray { + get { + return ((ushort[])(curObj["SecondaryVlanIdArray"])); + } + set { + curObj["SecondaryVlanIdArray"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The trunk vlan ID bitmap in trunk mode.")] + public ushort[] TrunkVlanIdArray { + get { + return ((ushort[])(curObj["TrunkVlanIdArray"])); + } + set { + curObj["TrunkVlanIdArray"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAccessVlanId() { + if ((this.IsAccessVlanIdNull == false)) { + return true; + } + return false; + } + + private void ResetAccessVlanId() { + curObj["AccessVlanId"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeNativeVlanId() { + if ((this.IsNativeVlanIdNull == false)) { + return true; + } + return false; + } + + private void ResetNativeVlanId() { + curObj["NativeVlanId"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeOperationMode() { + if ((this.IsOperationModeNull == false)) { + return true; + } + return false; + } + + private void ResetOperationMode() { + curObj["OperationMode"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializePrimaryVlanId() { + if ((this.IsPrimaryVlanIdNull == false)) { + return true; + } + return false; + } + + private void ResetPrimaryVlanId() { + curObj["PrimaryVlanId"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetPruneVlanIdArray() { + curObj["PruneVlanIdArray"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializePvlanMode() { + if ((this.IsPvlanModeNull == false)) { + return true; + } + return false; + } + + private void ResetPvlanMode() { + curObj["PvlanMode"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeSecondaryVlanId() { + if ((this.IsSecondaryVlanIdNull == false)) { + return true; + } + return false; + } + + private void ResetSecondaryVlanId() { + curObj["SecondaryVlanId"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetSecondaryVlanIdArray() { + curObj["SecondaryVlanIdArray"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetTrunkVlanIdArray() { + curObj["TrunkVlanIdArray"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_EthernetSwitchPortVlanSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static EthernetSwitchPortVlanSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static EthernetSwitchPortVlanSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static EthernetSwitchPortVlanSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static EthernetSwitchPortVlanSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_EthernetSwitchPortVlanSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new EthernetSwitchPortVlanSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static EthernetSwitchPortVlanSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_EthernetSwitchPortVlanSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new EthernetSwitchPortVlanSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static EthernetSwitchPortVlanSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new EthernetSwitchPortVlanSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public enum OperationModeValues { + + Access = 1, + + Trunk = 2, + + Private = 3, + + NULL_ENUM_VALUE = 0, + } + + public enum PvlanModeValues { + + Isolated = 1, + + Community = 2, + + Promiscuous = 3, + + NULL_ENUM_VALUE = 0, + } + + // Enumerator implementation for enumerating instances of the class. + public class EthernetSwitchPortVlanSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public EthernetSwitchPortVlanSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new EthernetSwitchPortVlanSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new EthernetSwitchPortVlanSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class EthernetSwitchPortVlanSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public EthernetSwitchPortVlanSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new EthernetSwitchPortVlanSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ExternalEthernetPort.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ExternalEthernetPort.cs index c5138852547b..acf4923e810b 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ExternalEthernetPort.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ExternalEthernetPort.cs @@ -1,2087 +1,2087 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_ExternalEthernetPort - public class ExternalEthernetPort : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_ExternalEthernetPort"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public ExternalEthernetPort() { - this.InitializeObject(null, null, null); - } - - public ExternalEthernetPort(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(null, new System.Management.ManagementPath(ExternalEthernetPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); - } - - public ExternalEthernetPort(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ExternalEthernetPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); - } - - public ExternalEthernetPort(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public ExternalEthernetPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public ExternalEthernetPort(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public ExternalEthernetPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public ExternalEthernetPort(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public ExternalEthernetPort(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsActiveMaximumTransmissionUnitNull { - get { - if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong ActiveMaximumTransmissionUnit { - get { - if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["ActiveMaximumTransmissionUnit"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AdditionalAvailability { - get { - return ((ushort[])(curObj["AdditionalAvailability"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutoSenseNull { - get { - if ((curObj["AutoSense"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutoSense { - get { - if ((curObj["AutoSense"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutoSense"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAvailabilityNull { - get { - if ((curObj["Availability"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort Availability { - get { - if ((curObj["Availability"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["Availability"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] Capabilities { - get { - return ((ushort[])(curObj["Capabilities"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] CapabilityDescriptions { - get { - return ((string[])(curObj["CapabilityDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string DeviceID { - get { - return ((string)(curObj["DeviceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] EnabledCapabilities { - get { - return ((ushort[])(curObj["EnabledCapabilities"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsErrorClearedNull { - get { - if ((curObj["ErrorCleared"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool ErrorCleared { - get { - if ((curObj["ErrorCleared"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["ErrorCleared"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ErrorDescription { - get { - return ((string)(curObj["ErrorDescription"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsFullDuplexNull { - get { - if ((curObj["FullDuplex"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool FullDuplex { - get { - if ((curObj["FullDuplex"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["FullDuplex"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] IdentifyingDescriptions { - get { - return ((string[])(curObj["IdentifyingDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsIsBoundNull { - get { - if ((curObj["IsBound"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("If this property is true, then this Ethernet port can be connected to the switche" + - "s and thus can provide connectivity to virtual machine. If this property is fals" + - "e, then this Ethernet is not being used by the virtual machine networking archit" + - "ecture.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool IsBound { - get { - if ((curObj["IsBound"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["IsBound"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLastErrorCodeNull { - get { - if ((curObj["LastErrorCode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint LastErrorCode { - get { - if ((curObj["LastErrorCode"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["LastErrorCode"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLinkTechnologyNull { - get { - if ((curObj["LinkTechnology"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort LinkTechnology { - get { - if ((curObj["LinkTechnology"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["LinkTechnology"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxDataSizeNull { - get { - if ((curObj["MaxDataSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint MaxDataSize { - get { - if ((curObj["MaxDataSize"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["MaxDataSize"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxQuiesceTimeNull { - get { - if ((curObj["MaxQuiesceTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxQuiesceTime { - get { - if ((curObj["MaxQuiesceTime"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxQuiesceTime"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxSpeedNull { - get { - if ((curObj["MaxSpeed"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxSpeed { - get { - if ((curObj["MaxSpeed"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxSpeed"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] NetworkAddresses { - get { - return ((string[])(curObj["NetworkAddresses"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherEnabledCapabilities { - get { - return ((string[])(curObj["OtherEnabledCapabilities"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherIdentifyingInfo { - get { - return ((string[])(curObj["OtherIdentifyingInfo"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherLinkTechnology { - get { - return ((string)(curObj["OtherLinkTechnology"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherNetworkPortType { - get { - return ((string)(curObj["OtherNetworkPortType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherPortType { - get { - return ((string)(curObj["OtherPortType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PermanentAddress { - get { - return ((string)(curObj["PermanentAddress"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPortNumberNull { - get { - if ((curObj["PortNumber"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PortNumber { - get { - if ((curObj["PortNumber"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PortNumber"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPortTypeNull { - get { - if ((curObj["PortType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PortType { - get { - if ((curObj["PortType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PortType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] PowerManagementCapabilities { - get { - return ((ushort[])(curObj["PowerManagementCapabilities"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPowerManagementSupportedNull { - get { - if ((curObj["PowerManagementSupported"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool PowerManagementSupported { - get { - if ((curObj["PowerManagementSupported"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["PowerManagementSupported"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPowerOnHoursNull { - get { - if ((curObj["PowerOnHours"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong PowerOnHours { - get { - if ((curObj["PowerOnHours"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["PowerOnHours"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedSpeedNull { - get { - if ((curObj["RequestedSpeed"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong RequestedSpeed { - get { - if ((curObj["RequestedSpeed"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["RequestedSpeed"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSpeedNull { - get { - if ((curObj["Speed"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Speed { - get { - if ((curObj["Speed"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Speed"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStatusInfoNull { - get { - if ((curObj["StatusInfo"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort StatusInfo { - get { - if ((curObj["StatusInfo"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["StatusInfo"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSupportedMaximumTransmissionUnitNull { - get { - if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong SupportedMaximumTransmissionUnit { - get { - if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["SupportedMaximumTransmissionUnit"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemCreationClassName { - get { - return ((string)(curObj["SystemCreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemName { - get { - return ((string)(curObj["SystemName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTotalPowerOnHoursNull { - get { - if ((curObj["TotalPowerOnHours"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong TotalPowerOnHours { - get { - if ((curObj["TotalPowerOnHours"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["TotalPowerOnHours"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsUsageRestrictionNull { - get { - if ((curObj["UsageRestriction"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort UsageRestriction { - get { - if ((curObj["UsageRestriction"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["UsageRestriction"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeActiveMaximumTransmissionUnit() { - if ((this.IsActiveMaximumTransmissionUnitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutoSense() { - if ((this.IsAutoSenseNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAvailability() { - if ((this.IsAvailabilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeErrorCleared() { - if ((this.IsErrorClearedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeFullDuplex() { - if ((this.IsFullDuplexNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeIsBound() { - if ((this.IsIsBoundNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLastErrorCode() { - if ((this.IsLastErrorCodeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLinkTechnology() { - if ((this.IsLinkTechnologyNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxDataSize() { - if ((this.IsMaxDataSizeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxQuiesceTime() { - if ((this.IsMaxQuiesceTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxSpeed() { - if ((this.IsMaxSpeedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePortNumber() { - if ((this.IsPortNumberNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePortType() { - if ((this.IsPortTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePowerManagementSupported() { - if ((this.IsPowerManagementSupportedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePowerOnHours() { - if ((this.IsPowerOnHoursNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedSpeed() { - if ((this.IsRequestedSpeedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeSpeed() { - if ((this.IsSpeedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStatusInfo() { - if ((this.IsStatusInfoNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeSupportedMaximumTransmissionUnit() { - if ((this.IsSupportedMaximumTransmissionUnitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTotalPowerOnHours() { - if ((this.IsTotalPowerOnHoursNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeUsageRestriction() { - if ((this.IsUsageRestrictionNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_ExternalEthernetPort"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",DeviceID=", string.Concat("\"", string.Concat(keyDeviceID, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static ExternalEthernetPortCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static ExternalEthernetPortCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static ExternalEthernetPortCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static ExternalEthernetPortCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_ExternalEthernetPort"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new ExternalEthernetPortCollection(clsObject.GetInstances(enumOptions)); - } - - public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ExternalEthernetPort", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new ExternalEthernetPortCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static ExternalEthernetPort CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new ExternalEthernetPort(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint EnableDevice(bool Enabled) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("EnableDevice"); - inParams["Enabled"] = ((bool)(Enabled)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnableDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint OnlineDevice(bool Online) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("OnlineDevice"); - inParams["Online"] = ((bool)(Online)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("OnlineDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint QuiesceDevice(bool Quiesce) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("QuiesceDevice"); - inParams["Quiesce"] = ((bool)(Quiesce)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("QuiesceDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint Reset() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("Reset", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RestoreProperties() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RestoreProperties", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint SaveProperties() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SaveProperties", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint SetPowerState(ushort PowerState, System.DateTime Time) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); - inParams["PowerState"] = ((ushort)(PowerState)); - inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class ExternalEthernetPortCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public ExternalEthernetPortCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new ExternalEthernetPort(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new ExternalEthernetPortEnumerator(privColObj.GetEnumerator()); - } - - public class ExternalEthernetPortEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public ExternalEthernetPortEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new ExternalEthernetPort(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_ExternalEthernetPort + public class ExternalEthernetPort : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_ExternalEthernetPort"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public ExternalEthernetPort() { + this.InitializeObject(null, null, null); + } + + public ExternalEthernetPort(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(null, new System.Management.ManagementPath(ExternalEthernetPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); + } + + public ExternalEthernetPort(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ExternalEthernetPort.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); + } + + public ExternalEthernetPort(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public ExternalEthernetPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public ExternalEthernetPort(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public ExternalEthernetPort(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public ExternalEthernetPort(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public ExternalEthernetPort(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsActiveMaximumTransmissionUnitNull { + get { + if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong ActiveMaximumTransmissionUnit { + get { + if ((curObj["ActiveMaximumTransmissionUnit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["ActiveMaximumTransmissionUnit"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AdditionalAvailability { + get { + return ((ushort[])(curObj["AdditionalAvailability"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutoSenseNull { + get { + if ((curObj["AutoSense"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutoSense { + get { + if ((curObj["AutoSense"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutoSense"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAvailabilityNull { + get { + if ((curObj["Availability"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort Availability { + get { + if ((curObj["Availability"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["Availability"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] Capabilities { + get { + return ((ushort[])(curObj["Capabilities"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] CapabilityDescriptions { + get { + return ((string[])(curObj["CapabilityDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string DeviceID { + get { + return ((string)(curObj["DeviceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] EnabledCapabilities { + get { + return ((ushort[])(curObj["EnabledCapabilities"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsErrorClearedNull { + get { + if ((curObj["ErrorCleared"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool ErrorCleared { + get { + if ((curObj["ErrorCleared"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["ErrorCleared"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ErrorDescription { + get { + return ((string)(curObj["ErrorDescription"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsFullDuplexNull { + get { + if ((curObj["FullDuplex"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool FullDuplex { + get { + if ((curObj["FullDuplex"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["FullDuplex"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] IdentifyingDescriptions { + get { + return ((string[])(curObj["IdentifyingDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsIsBoundNull { + get { + if ((curObj["IsBound"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("If this property is true, then this Ethernet port can be connected to the switche" + + "s and thus can provide connectivity to virtual machine. If this property is fals" + + "e, then this Ethernet is not being used by the virtual machine networking archit" + + "ecture.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool IsBound { + get { + if ((curObj["IsBound"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["IsBound"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLastErrorCodeNull { + get { + if ((curObj["LastErrorCode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint LastErrorCode { + get { + if ((curObj["LastErrorCode"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["LastErrorCode"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLinkTechnologyNull { + get { + if ((curObj["LinkTechnology"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort LinkTechnology { + get { + if ((curObj["LinkTechnology"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["LinkTechnology"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxDataSizeNull { + get { + if ((curObj["MaxDataSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint MaxDataSize { + get { + if ((curObj["MaxDataSize"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["MaxDataSize"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxQuiesceTimeNull { + get { + if ((curObj["MaxQuiesceTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxQuiesceTime { + get { + if ((curObj["MaxQuiesceTime"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxQuiesceTime"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxSpeedNull { + get { + if ((curObj["MaxSpeed"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxSpeed { + get { + if ((curObj["MaxSpeed"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxSpeed"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] NetworkAddresses { + get { + return ((string[])(curObj["NetworkAddresses"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherEnabledCapabilities { + get { + return ((string[])(curObj["OtherEnabledCapabilities"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherIdentifyingInfo { + get { + return ((string[])(curObj["OtherIdentifyingInfo"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherLinkTechnology { + get { + return ((string)(curObj["OtherLinkTechnology"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherNetworkPortType { + get { + return ((string)(curObj["OtherNetworkPortType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherPortType { + get { + return ((string)(curObj["OtherPortType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PermanentAddress { + get { + return ((string)(curObj["PermanentAddress"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPortNumberNull { + get { + if ((curObj["PortNumber"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PortNumber { + get { + if ((curObj["PortNumber"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PortNumber"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPortTypeNull { + get { + if ((curObj["PortType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PortType { + get { + if ((curObj["PortType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PortType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] PowerManagementCapabilities { + get { + return ((ushort[])(curObj["PowerManagementCapabilities"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPowerManagementSupportedNull { + get { + if ((curObj["PowerManagementSupported"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool PowerManagementSupported { + get { + if ((curObj["PowerManagementSupported"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["PowerManagementSupported"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPowerOnHoursNull { + get { + if ((curObj["PowerOnHours"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong PowerOnHours { + get { + if ((curObj["PowerOnHours"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["PowerOnHours"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedSpeedNull { + get { + if ((curObj["RequestedSpeed"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong RequestedSpeed { + get { + if ((curObj["RequestedSpeed"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["RequestedSpeed"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSpeedNull { + get { + if ((curObj["Speed"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Speed { + get { + if ((curObj["Speed"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Speed"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStatusInfoNull { + get { + if ((curObj["StatusInfo"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort StatusInfo { + get { + if ((curObj["StatusInfo"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["StatusInfo"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSupportedMaximumTransmissionUnitNull { + get { + if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong SupportedMaximumTransmissionUnit { + get { + if ((curObj["SupportedMaximumTransmissionUnit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["SupportedMaximumTransmissionUnit"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemCreationClassName { + get { + return ((string)(curObj["SystemCreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemName { + get { + return ((string)(curObj["SystemName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTotalPowerOnHoursNull { + get { + if ((curObj["TotalPowerOnHours"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong TotalPowerOnHours { + get { + if ((curObj["TotalPowerOnHours"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["TotalPowerOnHours"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsUsageRestrictionNull { + get { + if ((curObj["UsageRestriction"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort UsageRestriction { + get { + if ((curObj["UsageRestriction"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["UsageRestriction"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeActiveMaximumTransmissionUnit() { + if ((this.IsActiveMaximumTransmissionUnitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutoSense() { + if ((this.IsAutoSenseNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAvailability() { + if ((this.IsAvailabilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeErrorCleared() { + if ((this.IsErrorClearedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeFullDuplex() { + if ((this.IsFullDuplexNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeIsBound() { + if ((this.IsIsBoundNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLastErrorCode() { + if ((this.IsLastErrorCodeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLinkTechnology() { + if ((this.IsLinkTechnologyNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxDataSize() { + if ((this.IsMaxDataSizeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxQuiesceTime() { + if ((this.IsMaxQuiesceTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxSpeed() { + if ((this.IsMaxSpeedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePortNumber() { + if ((this.IsPortNumberNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePortType() { + if ((this.IsPortTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePowerManagementSupported() { + if ((this.IsPowerManagementSupportedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePowerOnHours() { + if ((this.IsPowerOnHoursNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedSpeed() { + if ((this.IsRequestedSpeedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeSpeed() { + if ((this.IsSpeedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStatusInfo() { + if ((this.IsStatusInfoNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeSupportedMaximumTransmissionUnit() { + if ((this.IsSupportedMaximumTransmissionUnitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTotalPowerOnHours() { + if ((this.IsTotalPowerOnHoursNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeUsageRestriction() { + if ((this.IsUsageRestrictionNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_ExternalEthernetPort"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",DeviceID=", string.Concat("\"", string.Concat(keyDeviceID, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static ExternalEthernetPortCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static ExternalEthernetPortCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static ExternalEthernetPortCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static ExternalEthernetPortCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_ExternalEthernetPort"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new ExternalEthernetPortCollection(clsObject.GetInstances(enumOptions)); + } + + public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static ExternalEthernetPortCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ExternalEthernetPort", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new ExternalEthernetPortCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static ExternalEthernetPort CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new ExternalEthernetPort(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint EnableDevice(bool Enabled) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("EnableDevice"); + inParams["Enabled"] = ((bool)(Enabled)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnableDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint OnlineDevice(bool Online) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("OnlineDevice"); + inParams["Online"] = ((bool)(Online)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("OnlineDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint QuiesceDevice(bool Quiesce) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("QuiesceDevice"); + inParams["Quiesce"] = ((bool)(Quiesce)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("QuiesceDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint Reset() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("Reset", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RestoreProperties() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RestoreProperties", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint SaveProperties() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SaveProperties", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint SetPowerState(ushort PowerState, System.DateTime Time) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); + inParams["PowerState"] = ((ushort)(PowerState)); + inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class ExternalEthernetPortCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public ExternalEthernetPortCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new ExternalEthernetPort(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new ExternalEthernetPortEnumerator(privColObj.GetEnumerator()); + } + + public class ExternalEthernetPortEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public ExternalEthernetPortEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new ExternalEthernetPort(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ImageManagementService.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ImageManagementService.cs index ff27854e8d52..ba96348416e2 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ImageManagementService.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ImageManagementService.cs @@ -1,1525 +1,1525 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_ImageManagementService - public class ImageManagementService : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_ImageManagementService"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public ImageManagementService() { - this.InitializeObject(null, null, null); - } - - public ImageManagementService(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(null, new System.Management.ManagementPath(ImageManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public ImageManagementService(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ImageManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public ImageManagementService(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public ImageManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public ImageManagementService(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public ImageManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public ImageManagementService(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public ImageManagementService(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerContact { - get { - return ((string)(curObj["PrimaryOwnerContact"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerName { - get { - return ((string)(curObj["PrimaryOwnerName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStartedNull { - get { - if ((curObj["Started"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool Started { - get { - if ((curObj["Started"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["Started"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string StartMode { - get { - return ((string)(curObj["StartMode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemCreationClassName { - get { - return ((string)(curObj["SystemCreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemName { - get { - return ((string)(curObj["SystemName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStarted() { - if ((this.IsStartedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_ImageManagementService"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static ImageManagementServiceCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static ImageManagementServiceCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static ImageManagementServiceCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static ImageManagementServiceCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_ImageManagementService"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new ImageManagementServiceCollection(clsObject.GetInstances(enumOptions)); - } - - public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ImageManagementService", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new ImageManagementServiceCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static ImageManagementService CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new ImageManagementService(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint AttachVirtualHardDisk(bool AssignDriveLetter, string Path, bool ReadOnly, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("AttachVirtualHardDisk"); - inParams["AssignDriveLetter"] = ((bool)(AssignDriveLetter)); - inParams["Path"] = ((string)(Path)); - inParams["ReadOnly"] = ((bool)(ReadOnly)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AttachVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint CompactVirtualHardDisk(ushort Mode, string Path, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("CompactVirtualHardDisk"); - inParams["Mode"] = ((ushort)(Mode)); - inParams["Path"] = ((string)(Path)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("CompactVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ConvertVirtualHardDisk(string SourcePath, string VirtualDiskSettingData, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ConvertVirtualHardDisk"); - inParams["SourcePath"] = ((string)(SourcePath)); - inParams["VirtualDiskSettingData"] = ((string)(VirtualDiskSettingData)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ConvertVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint CreateVirtualFloppyDisk(string Path, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("CreateVirtualFloppyDisk"); - inParams["Path"] = ((string)(Path)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("CreateVirtualFloppyDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint CreateVirtualHardDisk(string VirtualDiskSettingData, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("CreateVirtualHardDisk"); - inParams["VirtualDiskSettingData"] = ((string)(VirtualDiskSettingData)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("CreateVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GetVirtualHardDiskSettingData(string Path, out System.Management.ManagementPath Job, out string SettingData) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("GetVirtualHardDiskSettingData"); - inParams["Path"] = ((string)(Path)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetVirtualHardDiskSettingData", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - SettingData = System.Convert.ToString(outParams.Properties["SettingData"].Value); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - SettingData = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GetVirtualHardDiskState(string Path, out System.Management.ManagementPath Job, out string State) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("GetVirtualHardDiskState"); - inParams["Path"] = ((string)(Path)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetVirtualHardDiskState", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - State = System.Convert.ToString(outParams.Properties["State"].Value); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - State = null; - return System.Convert.ToUInt32(0); - } - } - - public uint MergeVirtualHardDisk(string DestinationPath, string SourcePath, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("MergeVirtualHardDisk"); - inParams["DestinationPath"] = ((string)(DestinationPath)); - inParams["SourcePath"] = ((string)(SourcePath)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("MergeVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ResizeVirtualHardDisk(ulong MaxInternalSize, string Path, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ResizeVirtualHardDisk"); - inParams["MaxInternalSize"] = ((ulong)(MaxInternalSize)); - inParams["Path"] = ((string)(Path)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ResizeVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint SetParentVirtualHardDisk(string ChildPath, bool IgnoreIDMismatch, string LeafPath, string ParentPath, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetParentVirtualHardDisk"); - inParams["ChildPath"] = ((string)(ChildPath)); - inParams["IgnoreIDMismatch"] = ((bool)(IgnoreIDMismatch)); - inParams["LeafPath"] = ((string)(LeafPath)); - inParams["ParentPath"] = ((string)(ParentPath)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetParentVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint SetVirtualHardDiskSettingData(string VirtualDiskSettingData, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetVirtualHardDiskSettingData"); - inParams["VirtualDiskSettingData"] = ((string)(VirtualDiskSettingData)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetVirtualHardDiskSettingData", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint StartService() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StartService", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint StopService() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StopService", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint ValidateVirtualHardDisk(string Path, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ValidateVirtualHardDisk"); - inParams["Path"] = ((string)(Path)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ValidateVirtualHardDisk", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class ImageManagementServiceCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public ImageManagementServiceCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new ImageManagementService(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new ImageManagementServiceEnumerator(privColObj.GetEnumerator()); - } - - public class ImageManagementServiceEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public ImageManagementServiceEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new ImageManagementService(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_ImageManagementService + public class ImageManagementService : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_ImageManagementService"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public ImageManagementService() { + this.InitializeObject(null, null, null); + } + + public ImageManagementService(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(null, new System.Management.ManagementPath(ImageManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public ImageManagementService(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ImageManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public ImageManagementService(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public ImageManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public ImageManagementService(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public ImageManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public ImageManagementService(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public ImageManagementService(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerContact { + get { + return ((string)(curObj["PrimaryOwnerContact"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerName { + get { + return ((string)(curObj["PrimaryOwnerName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStartedNull { + get { + if ((curObj["Started"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool Started { + get { + if ((curObj["Started"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["Started"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string StartMode { + get { + return ((string)(curObj["StartMode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemCreationClassName { + get { + return ((string)(curObj["SystemCreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemName { + get { + return ((string)(curObj["SystemName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStarted() { + if ((this.IsStartedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_ImageManagementService"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static ImageManagementServiceCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static ImageManagementServiceCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static ImageManagementServiceCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static ImageManagementServiceCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_ImageManagementService"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new ImageManagementServiceCollection(clsObject.GetInstances(enumOptions)); + } + + public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static ImageManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ImageManagementService", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new ImageManagementServiceCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static ImageManagementService CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new ImageManagementService(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint AttachVirtualHardDisk(bool AssignDriveLetter, string Path, bool ReadOnly, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("AttachVirtualHardDisk"); + inParams["AssignDriveLetter"] = ((bool)(AssignDriveLetter)); + inParams["Path"] = ((string)(Path)); + inParams["ReadOnly"] = ((bool)(ReadOnly)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AttachVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint CompactVirtualHardDisk(ushort Mode, string Path, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("CompactVirtualHardDisk"); + inParams["Mode"] = ((ushort)(Mode)); + inParams["Path"] = ((string)(Path)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("CompactVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ConvertVirtualHardDisk(string SourcePath, string VirtualDiskSettingData, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ConvertVirtualHardDisk"); + inParams["SourcePath"] = ((string)(SourcePath)); + inParams["VirtualDiskSettingData"] = ((string)(VirtualDiskSettingData)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ConvertVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint CreateVirtualFloppyDisk(string Path, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("CreateVirtualFloppyDisk"); + inParams["Path"] = ((string)(Path)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("CreateVirtualFloppyDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint CreateVirtualHardDisk(string VirtualDiskSettingData, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("CreateVirtualHardDisk"); + inParams["VirtualDiskSettingData"] = ((string)(VirtualDiskSettingData)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("CreateVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GetVirtualHardDiskSettingData(string Path, out System.Management.ManagementPath Job, out string SettingData) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("GetVirtualHardDiskSettingData"); + inParams["Path"] = ((string)(Path)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetVirtualHardDiskSettingData", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + SettingData = System.Convert.ToString(outParams.Properties["SettingData"].Value); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + SettingData = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GetVirtualHardDiskState(string Path, out System.Management.ManagementPath Job, out string State) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("GetVirtualHardDiskState"); + inParams["Path"] = ((string)(Path)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetVirtualHardDiskState", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + State = System.Convert.ToString(outParams.Properties["State"].Value); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + State = null; + return System.Convert.ToUInt32(0); + } + } + + public uint MergeVirtualHardDisk(string DestinationPath, string SourcePath, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("MergeVirtualHardDisk"); + inParams["DestinationPath"] = ((string)(DestinationPath)); + inParams["SourcePath"] = ((string)(SourcePath)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("MergeVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ResizeVirtualHardDisk(ulong MaxInternalSize, string Path, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ResizeVirtualHardDisk"); + inParams["MaxInternalSize"] = ((ulong)(MaxInternalSize)); + inParams["Path"] = ((string)(Path)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ResizeVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint SetParentVirtualHardDisk(string ChildPath, bool IgnoreIDMismatch, string LeafPath, string ParentPath, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetParentVirtualHardDisk"); + inParams["ChildPath"] = ((string)(ChildPath)); + inParams["IgnoreIDMismatch"] = ((bool)(IgnoreIDMismatch)); + inParams["LeafPath"] = ((string)(LeafPath)); + inParams["ParentPath"] = ((string)(ParentPath)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetParentVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint SetVirtualHardDiskSettingData(string VirtualDiskSettingData, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetVirtualHardDiskSettingData"); + inParams["VirtualDiskSettingData"] = ((string)(VirtualDiskSettingData)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetVirtualHardDiskSettingData", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint StartService() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StartService", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint StopService() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StopService", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint ValidateVirtualHardDisk(string Path, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ValidateVirtualHardDisk"); + inParams["Path"] = ((string)(Path)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ValidateVirtualHardDisk", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class ImageManagementServiceCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public ImageManagementServiceCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new ImageManagementService(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new ImageManagementServiceEnumerator(privColObj.GetEnumerator()); + } + + public class ImageManagementServiceEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public ImageManagementServiceEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new ImageManagementService(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponent.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponent.cs index d9f6c5667a66..aaf02d6beafb 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponent.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponent.cs @@ -1,1615 +1,1615 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 -{ - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_KvpExchangeComponent - public class KvpExchangeComponent : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_KvpExchangeComponent"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public KvpExchangeComponent() { - this.InitializeObject(null, null, null); - } - - public KvpExchangeComponent(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(null, new System.Management.ManagementPath(KvpExchangeComponent.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); - } - - public KvpExchangeComponent(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(KvpExchangeComponent.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); - } - - public KvpExchangeComponent(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public KvpExchangeComponent(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public KvpExchangeComponent(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public KvpExchangeComponent(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public KvpExchangeComponent(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public KvpExchangeComponent(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AdditionalAvailability { - get { - return ((ushort[])(curObj["AdditionalAvailability"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAvailabilityNull { - get { - if ((curObj["Availability"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort Availability { - get { - if ((curObj["Availability"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["Availability"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string DeviceID { - get { - return ((string)(curObj["DeviceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsErrorClearedNull { - get { - if ((curObj["ErrorCleared"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool ErrorCleared { - get { - if ((curObj["ErrorCleared"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["ErrorCleared"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ErrorDescription { - get { - return ((string)(curObj["ErrorDescription"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"An array of embedded Msvm_KvpExchangeDataItem instances which contain the set of key-value pairs that components running within the guest operating system have pushed up to be available for access by external clients. This array will not contain any intrinsic items that are pushed by the integration component directly.")] - public string[] GuestExchangeItems { - get { - return ((string[])(curObj["GuestExchangeItems"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"An array of embedded Msvm_KvpExchangeDataItem instances which contain the set of key-value pairs that the guest operating system has pushed up to be available for access by external clients. This array will not contain any data items pushed by other components running within the guest operating system.")] - public string[] GuestIntrinsicExchangeItems { - get { - return ((string[])(curObj["GuestIntrinsicExchangeItems"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] IdentifyingDescriptions { - get { - return ((string[])(curObj["IdentifyingDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLastErrorCodeNull { - get { - if ((curObj["LastErrorCode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint LastErrorCode { - get { - if ((curObj["LastErrorCode"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["LastErrorCode"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxQuiesceTimeNull { - get { - if ((curObj["MaxQuiesceTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxQuiesceTime { - get { - if ((curObj["MaxQuiesceTime"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxQuiesceTime"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherIdentifyingInfo { - get { - return ((string[])(curObj["OtherIdentifyingInfo"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] PowerManagementCapabilities { - get { - return ((ushort[])(curObj["PowerManagementCapabilities"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPowerManagementSupportedNull { - get { - if ((curObj["PowerManagementSupported"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool PowerManagementSupported { - get { - if ((curObj["PowerManagementSupported"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["PowerManagementSupported"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPowerOnHoursNull { - get { - if ((curObj["PowerOnHours"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong PowerOnHours { - get { - if ((curObj["PowerOnHours"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["PowerOnHours"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStatusInfoNull { - get { - if ((curObj["StatusInfo"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort StatusInfo { - get { - if ((curObj["StatusInfo"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["StatusInfo"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemCreationClassName { - get { - return ((string)(curObj["SystemCreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemName { - get { - return ((string)(curObj["SystemName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTotalPowerOnHoursNull { - get { - if ((curObj["TotalPowerOnHours"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong TotalPowerOnHours { - get { - if ((curObj["TotalPowerOnHours"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["TotalPowerOnHours"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAvailability() { - if ((this.IsAvailabilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeErrorCleared() { - if ((this.IsErrorClearedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLastErrorCode() { - if ((this.IsLastErrorCodeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxQuiesceTime() { - if ((this.IsMaxQuiesceTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePowerManagementSupported() { - if ((this.IsPowerManagementSupportedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePowerOnHours() { - if ((this.IsPowerOnHoursNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStatusInfo() { - if ((this.IsStatusInfoNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTotalPowerOnHours() { - if ((this.IsTotalPowerOnHoursNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_KvpExchangeComponent"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",DeviceID=", string.Concat("\"", string.Concat(keyDeviceID, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static KvpExchangeComponentCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static KvpExchangeComponentCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static KvpExchangeComponentCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static KvpExchangeComponentCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_KvpExchangeComponent"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new KvpExchangeComponentCollection(clsObject.GetInstances(enumOptions)); - } - - public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_KvpExchangeComponent", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new KvpExchangeComponentCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static KvpExchangeComponent CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new KvpExchangeComponent(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint EnableDevice(bool Enabled) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("EnableDevice"); - inParams["Enabled"] = ((bool)(Enabled)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnableDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint OnlineDevice(bool Online) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("OnlineDevice"); - inParams["Online"] = ((bool)(Online)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("OnlineDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint QuiesceDevice(bool Quiesce) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("QuiesceDevice"); - inParams["Quiesce"] = ((bool)(Quiesce)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("QuiesceDevice", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint Reset() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("Reset", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RestoreProperties() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RestoreProperties", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint SaveProperties() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SaveProperties", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint SetPowerState(ushort PowerState, System.DateTime Time) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); - inParams["PowerState"] = ((ushort)(PowerState)); - inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class KvpExchangeComponentCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public KvpExchangeComponentCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new KvpExchangeComponent(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new KvpExchangeComponentEnumerator(privColObj.GetEnumerator()); - } - - public class KvpExchangeComponentEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public KvpExchangeComponentEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new KvpExchangeComponent(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 +{ + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_KvpExchangeComponent + public class KvpExchangeComponent : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_KvpExchangeComponent"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public KvpExchangeComponent() { + this.InitializeObject(null, null, null); + } + + public KvpExchangeComponent(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(null, new System.Management.ManagementPath(KvpExchangeComponent.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); + } + + public KvpExchangeComponent(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(KvpExchangeComponent.ConstructPath(keyCreationClassName, keyDeviceID, keySystemCreationClassName, keySystemName)), null); + } + + public KvpExchangeComponent(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public KvpExchangeComponent(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public KvpExchangeComponent(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public KvpExchangeComponent(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public KvpExchangeComponent(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public KvpExchangeComponent(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AdditionalAvailability { + get { + return ((ushort[])(curObj["AdditionalAvailability"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAvailabilityNull { + get { + if ((curObj["Availability"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort Availability { + get { + if ((curObj["Availability"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["Availability"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string DeviceID { + get { + return ((string)(curObj["DeviceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsErrorClearedNull { + get { + if ((curObj["ErrorCleared"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool ErrorCleared { + get { + if ((curObj["ErrorCleared"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["ErrorCleared"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ErrorDescription { + get { + return ((string)(curObj["ErrorDescription"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"An array of embedded Msvm_KvpExchangeDataItem instances which contain the set of key-value pairs that components running within the guest operating system have pushed up to be available for access by external clients. This array will not contain any intrinsic items that are pushed by the integration component directly.")] + public string[] GuestExchangeItems { + get { + return ((string[])(curObj["GuestExchangeItems"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"An array of embedded Msvm_KvpExchangeDataItem instances which contain the set of key-value pairs that the guest operating system has pushed up to be available for access by external clients. This array will not contain any data items pushed by other components running within the guest operating system.")] + public string[] GuestIntrinsicExchangeItems { + get { + return ((string[])(curObj["GuestIntrinsicExchangeItems"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] IdentifyingDescriptions { + get { + return ((string[])(curObj["IdentifyingDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLastErrorCodeNull { + get { + if ((curObj["LastErrorCode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint LastErrorCode { + get { + if ((curObj["LastErrorCode"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["LastErrorCode"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxQuiesceTimeNull { + get { + if ((curObj["MaxQuiesceTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxQuiesceTime { + get { + if ((curObj["MaxQuiesceTime"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxQuiesceTime"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherIdentifyingInfo { + get { + return ((string[])(curObj["OtherIdentifyingInfo"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] PowerManagementCapabilities { + get { + return ((ushort[])(curObj["PowerManagementCapabilities"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPowerManagementSupportedNull { + get { + if ((curObj["PowerManagementSupported"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool PowerManagementSupported { + get { + if ((curObj["PowerManagementSupported"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["PowerManagementSupported"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPowerOnHoursNull { + get { + if ((curObj["PowerOnHours"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong PowerOnHours { + get { + if ((curObj["PowerOnHours"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["PowerOnHours"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStatusInfoNull { + get { + if ((curObj["StatusInfo"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort StatusInfo { + get { + if ((curObj["StatusInfo"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["StatusInfo"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemCreationClassName { + get { + return ((string)(curObj["SystemCreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemName { + get { + return ((string)(curObj["SystemName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTotalPowerOnHoursNull { + get { + if ((curObj["TotalPowerOnHours"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong TotalPowerOnHours { + get { + if ((curObj["TotalPowerOnHours"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["TotalPowerOnHours"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAvailability() { + if ((this.IsAvailabilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeErrorCleared() { + if ((this.IsErrorClearedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLastErrorCode() { + if ((this.IsLastErrorCodeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxQuiesceTime() { + if ((this.IsMaxQuiesceTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePowerManagementSupported() { + if ((this.IsPowerManagementSupportedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePowerOnHours() { + if ((this.IsPowerOnHoursNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStatusInfo() { + if ((this.IsStatusInfoNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTotalPowerOnHours() { + if ((this.IsTotalPowerOnHoursNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyDeviceID, string keySystemCreationClassName, string keySystemName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_KvpExchangeComponent"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",DeviceID=", string.Concat("\"", string.Concat(keyDeviceID, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static KvpExchangeComponentCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static KvpExchangeComponentCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static KvpExchangeComponentCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static KvpExchangeComponentCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_KvpExchangeComponent"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new KvpExchangeComponentCollection(clsObject.GetInstances(enumOptions)); + } + + public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static KvpExchangeComponentCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_KvpExchangeComponent", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new KvpExchangeComponentCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static KvpExchangeComponent CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new KvpExchangeComponent(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint EnableDevice(bool Enabled) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("EnableDevice"); + inParams["Enabled"] = ((bool)(Enabled)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnableDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint OnlineDevice(bool Online) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("OnlineDevice"); + inParams["Online"] = ((bool)(Online)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("OnlineDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint QuiesceDevice(bool Quiesce) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("QuiesceDevice"); + inParams["Quiesce"] = ((bool)(Quiesce)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("QuiesceDevice", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint Reset() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("Reset", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RestoreProperties() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RestoreProperties", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint SaveProperties() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SaveProperties", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint SetPowerState(ushort PowerState, System.DateTime Time) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); + inParams["PowerState"] = ((ushort)(PowerState)); + inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class KvpExchangeComponentCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public KvpExchangeComponentCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new KvpExchangeComponent(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new KvpExchangeComponentEnumerator(privColObj.GetEnumerator()); + } + + public class KvpExchangeComponentEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public KvpExchangeComponentEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new KvpExchangeComponent(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponentSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponentSettingData.cs index 0832e3c92281..de15266595ea 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponentSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeComponentSettingData.cs @@ -15,1040 +15,1040 @@ // specific language governing permissions and limitations // under the License. -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 -{ - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_KvpExchangeComponentSettingData - public class KvpExchangeComponentSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_KvpExchangeComponentSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public KvpExchangeComponentSettingData() { - this.InitializeObject(null, null, null); - } - - public KvpExchangeComponentSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(KvpExchangeComponentSettingData.ConstructPath(keyInstanceID)), null); - } - - public KvpExchangeComponentSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(KvpExchangeComponentSettingData.ConstructPath(keyInstanceID)), null); - } - - public KvpExchangeComponentSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public KvpExchangeComponentSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public KvpExchangeComponentSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public KvpExchangeComponentSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public KvpExchangeComponentSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public KvpExchangeComponentSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Address { - get { - return ((string)(curObj["Address"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AddressOnParent { - get { - return ((string)(curObj["AddressOnParent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AllocationUnits { - get { - return ((string)(curObj["AllocationUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticAllocationNull { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticAllocation { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticAllocation"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticDeallocationNull { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticDeallocation { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticDeallocation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Connection { - get { - return ((string[])(curObj["Connection"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConsumerVisibilityNull { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ConsumerVisibility { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ConsumerVisibility"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 +{ + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_KvpExchangeComponentSettingData + public class KvpExchangeComponentSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_KvpExchangeComponentSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public KvpExchangeComponentSettingData() { + this.InitializeObject(null, null, null); + } + + public KvpExchangeComponentSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(KvpExchangeComponentSettingData.ConstructPath(keyInstanceID)), null); + } + + public KvpExchangeComponentSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(KvpExchangeComponentSettingData.ConstructPath(keyInstanceID)), null); + } + + public KvpExchangeComponentSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public KvpExchangeComponentSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public KvpExchangeComponentSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public KvpExchangeComponentSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public KvpExchangeComponentSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public KvpExchangeComponentSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Address { + get { + return ((string)(curObj["Address"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AddressOnParent { + get { + return ((string)(curObj["AddressOnParent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AllocationUnits { + get { + return ((string)(curObj["AllocationUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticAllocationNull { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticAllocation { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticAllocation"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticDeallocationNull { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticDeallocation { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticDeallocation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Connection { + get { + return ((string[])(curObj["Connection"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConsumerVisibilityNull { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ConsumerVisibility { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ConsumerVisibility"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"The enabled and disabled states of an element. Valid values are 2 (enabled) and 3 (disabled). The default value is 2 (enabled). -This is a read-only property, but it can be changed using the ModifyVirtualSystemResources method of the Msvm_VirtualSystemManagementService class.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("An array of Msvm_KvpExchangeDataItem instances.\nThis is a read-only property, but" + - " it can be changed using the AddKvpItems, ModifyKvpItems, and RemoveKvpItems met" + - "hods of the Msvm_VirtualSystemManagementService class.")] - public string[] HostExchangeItems { - get { - return ((string[])(curObj["HostExchangeItems"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"An array of Msvm_KvpExchangeDataItem instances containing the key/value pairs that are stored in the configuration file but not exchanged with the guest OS. This allows applications to store VM-specific data that does not need to be visible to the guest OS. The items are formatted the same as the items in the HostExchangeItems property except the Source property of the Msvm_KvpExchangeDataItem instance is set to 4. Each configuration file is limited to 128 key/value pairs, where each value field is allowed to be up to 16 KB in size and the key field is allowed to be up to512 bytes.")] - public string[] HostOnlyItems { - get { - return ((string[])(curObj["HostOnlyItems"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] HostResource { - get { - return ((string[])(curObj["HostResource"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitNull { - get { - if ((curObj["Limit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Limit { - get { - if ((curObj["Limit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Limit"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMappingBehaviorNull { - get { - if ((curObj["MappingBehavior"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort MappingBehavior { - get { - if ((curObj["MappingBehavior"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["MappingBehavior"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherResourceType { - get { - return ((string)(curObj["OtherResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PoolID { - get { - return ((string)(curObj["PoolID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReservationNull { - get { - if ((curObj["Reservation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Reservation { - get { - if ((curObj["Reservation"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Reservation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ResourceSubType { - get { - return ((string)(curObj["ResourceSubType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResourceTypeNull { - get { - if ((curObj["ResourceType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResourceType { - get { - if ((curObj["ResourceType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResourceType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualQuantityNull { - get { - if ((curObj["VirtualQuantity"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualQuantity { - get { - if ((curObj["VirtualQuantity"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualQuantity"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualQuantityUnits { - get { - return ((string)(curObj["VirtualQuantityUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsWeightNull { - get { - if ((curObj["Weight"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Weight { - get { - if ((curObj["Weight"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Weight"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAutomaticAllocation() { - if ((this.IsAutomaticAllocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticDeallocation() { - if ((this.IsAutomaticDeallocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConsumerVisibility() { - if ((this.IsConsumerVisibilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimit() { - if ((this.IsLimitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMappingBehavior() { - if ((this.IsMappingBehaviorNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReservation() { - if ((this.IsReservationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResourceType() { - if ((this.IsResourceTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualQuantity() { - if ((this.IsVirtualQuantityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeWeight() { - if ((this.IsWeightNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_KvpExchangeComponentSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static KvpExchangeComponentSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static KvpExchangeComponentSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static KvpExchangeComponentSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static KvpExchangeComponentSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_KvpExchangeComponentSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new KvpExchangeComponentSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_KvpExchangeComponentSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new KvpExchangeComponentSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static KvpExchangeComponentSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new KvpExchangeComponentSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class KvpExchangeComponentSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public KvpExchangeComponentSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new KvpExchangeComponentSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new KvpExchangeComponentSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class KvpExchangeComponentSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public KvpExchangeComponentSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new KvpExchangeComponentSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +This is a read-only property, but it can be changed using the ModifyVirtualSystemResources method of the Msvm_VirtualSystemManagementService class.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("An array of Msvm_KvpExchangeDataItem instances.\nThis is a read-only property, but" + + " it can be changed using the AddKvpItems, ModifyKvpItems, and RemoveKvpItems met" + + "hods of the Msvm_VirtualSystemManagementService class.")] + public string[] HostExchangeItems { + get { + return ((string[])(curObj["HostExchangeItems"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"An array of Msvm_KvpExchangeDataItem instances containing the key/value pairs that are stored in the configuration file but not exchanged with the guest OS. This allows applications to store VM-specific data that does not need to be visible to the guest OS. The items are formatted the same as the items in the HostExchangeItems property except the Source property of the Msvm_KvpExchangeDataItem instance is set to 4. Each configuration file is limited to 128 key/value pairs, where each value field is allowed to be up to 16 KB in size and the key field is allowed to be up to512 bytes.")] + public string[] HostOnlyItems { + get { + return ((string[])(curObj["HostOnlyItems"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] HostResource { + get { + return ((string[])(curObj["HostResource"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitNull { + get { + if ((curObj["Limit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Limit { + get { + if ((curObj["Limit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Limit"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMappingBehaviorNull { + get { + if ((curObj["MappingBehavior"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort MappingBehavior { + get { + if ((curObj["MappingBehavior"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["MappingBehavior"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherResourceType { + get { + return ((string)(curObj["OtherResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PoolID { + get { + return ((string)(curObj["PoolID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReservationNull { + get { + if ((curObj["Reservation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Reservation { + get { + if ((curObj["Reservation"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Reservation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ResourceSubType { + get { + return ((string)(curObj["ResourceSubType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResourceTypeNull { + get { + if ((curObj["ResourceType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResourceType { + get { + if ((curObj["ResourceType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResourceType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualQuantityNull { + get { + if ((curObj["VirtualQuantity"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualQuantity { + get { + if ((curObj["VirtualQuantity"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualQuantity"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualQuantityUnits { + get { + return ((string)(curObj["VirtualQuantityUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsWeightNull { + get { + if ((curObj["Weight"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Weight { + get { + if ((curObj["Weight"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Weight"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAutomaticAllocation() { + if ((this.IsAutomaticAllocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticDeallocation() { + if ((this.IsAutomaticDeallocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConsumerVisibility() { + if ((this.IsConsumerVisibilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimit() { + if ((this.IsLimitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMappingBehavior() { + if ((this.IsMappingBehaviorNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReservation() { + if ((this.IsReservationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResourceType() { + if ((this.IsResourceTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualQuantity() { + if ((this.IsVirtualQuantityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeWeight() { + if ((this.IsWeightNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_KvpExchangeComponentSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static KvpExchangeComponentSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static KvpExchangeComponentSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static KvpExchangeComponentSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static KvpExchangeComponentSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_KvpExchangeComponentSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new KvpExchangeComponentSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static KvpExchangeComponentSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_KvpExchangeComponentSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new KvpExchangeComponentSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static KvpExchangeComponentSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new KvpExchangeComponentSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class KvpExchangeComponentSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public KvpExchangeComponentSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new KvpExchangeComponentSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new KvpExchangeComponentSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class KvpExchangeComponentSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public KvpExchangeComponentSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new KvpExchangeComponentSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeDataItem.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeDataItem.cs index bf5eaae8e7c9..ffc1e9888ace 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeDataItem.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_KvpExchangeDataItem.cs @@ -1,670 +1,670 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 -{ - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_KvpExchangeDataItem - public class KvpExchangeDataItem : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_KvpExchangeDataItem"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public KvpExchangeDataItem() { - this.InitializeObject(null, null, null); - } - - public KvpExchangeDataItem(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public KvpExchangeDataItem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public KvpExchangeDataItem(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public KvpExchangeDataItem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public KvpExchangeDataItem(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public KvpExchangeDataItem(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Data { - get { - return ((string)(curObj["Data"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSourceNull { - get { - if ((curObj["Source"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort Source { - get { - if ((curObj["Source"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["Source"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeSource() { - if ((this.IsSourceNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath() { - string strPath = "ROOT\\virtualization\\v2:Msvm_KvpExchangeDataItem"; - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static KvpExchangeDataItemCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static KvpExchangeDataItemCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static KvpExchangeDataItemCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static KvpExchangeDataItemCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_KvpExchangeDataItem"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new KvpExchangeDataItemCollection(clsObject.GetInstances(enumOptions)); - } - - public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_KvpExchangeDataItem", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new KvpExchangeDataItemCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static KvpExchangeDataItem CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new KvpExchangeDataItem(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class KvpExchangeDataItemCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public KvpExchangeDataItemCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new KvpExchangeDataItem(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new KvpExchangeDataItemEnumerator(privColObj.GetEnumerator()); - } - - public class KvpExchangeDataItemEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public KvpExchangeDataItemEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new KvpExchangeDataItem(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 +{ + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_KvpExchangeDataItem + public class KvpExchangeDataItem : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_KvpExchangeDataItem"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public KvpExchangeDataItem() { + this.InitializeObject(null, null, null); + } + + public KvpExchangeDataItem(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public KvpExchangeDataItem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public KvpExchangeDataItem(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public KvpExchangeDataItem(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public KvpExchangeDataItem(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public KvpExchangeDataItem(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Data { + get { + return ((string)(curObj["Data"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSourceNull { + get { + if ((curObj["Source"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort Source { + get { + if ((curObj["Source"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["Source"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeSource() { + if ((this.IsSourceNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath() { + string strPath = "ROOT\\virtualization\\v2:Msvm_KvpExchangeDataItem"; + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static KvpExchangeDataItemCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static KvpExchangeDataItemCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static KvpExchangeDataItemCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static KvpExchangeDataItemCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_KvpExchangeDataItem"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new KvpExchangeDataItemCollection(clsObject.GetInstances(enumOptions)); + } + + public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static KvpExchangeDataItemCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_KvpExchangeDataItem", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new KvpExchangeDataItemCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static KvpExchangeDataItem CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new KvpExchangeDataItem(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class KvpExchangeDataItemCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public KvpExchangeDataItemCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new KvpExchangeDataItem(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new KvpExchangeDataItemEnumerator(privColObj.GetEnumerator()); + } + + public class KvpExchangeDataItemEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public KvpExchangeDataItemEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new KvpExchangeDataItem(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_LANEndpoint.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_LANEndpoint.cs index 453f528d4974..ee8563aadc5b 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_LANEndpoint.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_LANEndpoint.cs @@ -1,1422 +1,1422 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_LANEndpoint - public class LANEndpoint : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_LANEndpoint"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public LANEndpoint() { - this.InitializeObject(null, null, null); - } - - public LANEndpoint(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(null, new System.Management.ManagementPath(LANEndpoint.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public LANEndpoint(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(LANEndpoint.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public LANEndpoint(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public LANEndpoint(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public LANEndpoint(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public LANEndpoint(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public LANEndpoint(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public LANEndpoint(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] AliasAddresses { - get { - return ((string[])(curObj["AliasAddresses"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConnectedNull { - get { - if ((curObj["Connected"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("This property is set to TRUE if the LAN endpoint is connected to a switch port.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool Connected { - get { - if ((curObj["Connected"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["Connected"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] GroupAddresses { - get { - return ((string[])(curObj["GroupAddresses"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string LANID { - get { - return ((string)(curObj["LANID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLANTypeNull { - get { - if ((curObj["LANType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort LANType { - get { - if ((curObj["LANType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["LANType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string MACAddress { - get { - return ((string)(curObj["MACAddress"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxDataSizeNull { - get { - if ((curObj["MaxDataSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint MaxDataSize { - get { - if ((curObj["MaxDataSize"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["MaxDataSize"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string NameFormat { - get { - return ((string)(curObj["NameFormat"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherLANType { - get { - return ((string)(curObj["OtherLANType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherTypeDescription { - get { - return ((string)(curObj["OtherTypeDescription"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsProtocolIFTypeNull { - get { - if ((curObj["ProtocolIFType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ProtocolIFType { - get { - if ((curObj["ProtocolIFType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ProtocolIFType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsProtocolTypeNull { - get { - if ((curObj["ProtocolType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ProtocolType { - get { - if ((curObj["ProtocolType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ProtocolType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemCreationClassName { - get { - return ((string)(curObj["SystemCreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemName { - get { - return ((string)(curObj["SystemName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConnected() { - if ((this.IsConnectedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLANType() { - if ((this.IsLANTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxDataSize() { - if ((this.IsMaxDataSizeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeProtocolIFType() { - if ((this.IsProtocolIFTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeProtocolType() { - if ((this.IsProtocolTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_LANEndpoint"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static LANEndpointCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static LANEndpointCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static LANEndpointCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static LANEndpointCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_LANEndpoint"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new LANEndpointCollection(clsObject.GetInstances(enumOptions)); - } - - public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_LANEndpoint", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new LANEndpointCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static LANEndpoint CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new LANEndpoint(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class LANEndpointCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public LANEndpointCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new LANEndpoint(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new LANEndpointEnumerator(privColObj.GetEnumerator()); - } - - public class LANEndpointEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public LANEndpointEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new LANEndpoint(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_LANEndpoint + public class LANEndpoint : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_LANEndpoint"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public LANEndpoint() { + this.InitializeObject(null, null, null); + } + + public LANEndpoint(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(null, new System.Management.ManagementPath(LANEndpoint.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public LANEndpoint(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(LANEndpoint.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public LANEndpoint(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public LANEndpoint(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public LANEndpoint(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public LANEndpoint(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public LANEndpoint(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public LANEndpoint(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] AliasAddresses { + get { + return ((string[])(curObj["AliasAddresses"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConnectedNull { + get { + if ((curObj["Connected"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("This property is set to TRUE if the LAN endpoint is connected to a switch port.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool Connected { + get { + if ((curObj["Connected"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["Connected"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] GroupAddresses { + get { + return ((string[])(curObj["GroupAddresses"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string LANID { + get { + return ((string)(curObj["LANID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLANTypeNull { + get { + if ((curObj["LANType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort LANType { + get { + if ((curObj["LANType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["LANType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string MACAddress { + get { + return ((string)(curObj["MACAddress"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxDataSizeNull { + get { + if ((curObj["MaxDataSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint MaxDataSize { + get { + if ((curObj["MaxDataSize"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["MaxDataSize"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string NameFormat { + get { + return ((string)(curObj["NameFormat"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherLANType { + get { + return ((string)(curObj["OtherLANType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherTypeDescription { + get { + return ((string)(curObj["OtherTypeDescription"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsProtocolIFTypeNull { + get { + if ((curObj["ProtocolIFType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ProtocolIFType { + get { + if ((curObj["ProtocolIFType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ProtocolIFType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsProtocolTypeNull { + get { + if ((curObj["ProtocolType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ProtocolType { + get { + if ((curObj["ProtocolType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ProtocolType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemCreationClassName { + get { + return ((string)(curObj["SystemCreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemName { + get { + return ((string)(curObj["SystemName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConnected() { + if ((this.IsConnectedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLANType() { + if ((this.IsLANTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxDataSize() { + if ((this.IsMaxDataSizeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeProtocolIFType() { + if ((this.IsProtocolIFTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeProtocolType() { + if ((this.IsProtocolTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_LANEndpoint"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static LANEndpointCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static LANEndpointCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static LANEndpointCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static LANEndpointCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_LANEndpoint"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new LANEndpointCollection(clsObject.GetInstances(enumOptions)); + } + + public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static LANEndpointCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_LANEndpoint", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new LANEndpointCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static LANEndpoint CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new LANEndpoint(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class LANEndpointCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public LANEndpointCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new LANEndpoint(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new LANEndpointEnumerator(privColObj.GetEnumerator()); + } + + public class LANEndpointEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public LANEndpointEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new LANEndpoint(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_MemorySettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_MemorySettingData.cs index f57655ff8e88..d6cda05931de 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_MemorySettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_MemorySettingData.cs @@ -1,1163 +1,1163 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_MemorySettingData - public class MemorySettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_MemorySettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public MemorySettingData() { - this.InitializeObject(null, null, null); - } - - public MemorySettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(MemorySettingData.ConstructPath(keyInstanceID)), null); - } - - public MemorySettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(MemorySettingData.ConstructPath(keyInstanceID)), null); - } - - public MemorySettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public MemorySettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public MemorySettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public MemorySettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public MemorySettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public MemorySettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Address { - get { - return ((string)(curObj["Address"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AddressOnParent { - get { - return ((string)(curObj["AddressOnParent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AllocationUnits { - get { - return ((string)(curObj["AllocationUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticAllocationNull { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticAllocation { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticAllocation"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticDeallocationNull { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticDeallocation { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticDeallocation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Connection { - get { - return ((string[])(curObj["Connection"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConsumerVisibilityNull { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ConsumerVisibility { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ConsumerVisibility"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDynamicMemoryEnabledNull { - get { - if ((curObj["DynamicMemoryEnabled"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates if dynamic memory is enabled.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool DynamicMemoryEnabled { - get { - if ((curObj["DynamicMemoryEnabled"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["DynamicMemoryEnabled"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] HostResource { - get { - return ((string[])(curObj["HostResource"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsIsVirtualizedNull { - get { - if ((curObj["IsVirtualized"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"Indicates whether this device is virtualized or passed through, possibly using partitioning. When set to False, the underlying or host resource is utilized. At least one item shall be present in the DeviceID property. When set to True, the resource is virtualized and may not map directly to an underlying/host resource. Some implementations may support specific assignment for virtualized resources, in which case the host resource(s) are exposed using the DeviceID property. This property is always set to True.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool IsVirtualized { - get { - if ((curObj["IsVirtualized"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["IsVirtualized"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitNull { - get { - if ((curObj["Limit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Limit { - get { - if ((curObj["Limit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Limit"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMappingBehaviorNull { - get { - if ((curObj["MappingBehavior"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort MappingBehavior { - get { - if ((curObj["MappingBehavior"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["MappingBehavior"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxMemoryBlocksPerNumaNodeNull { - get { - if ((curObj["MaxMemoryBlocksPerNumaNode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum amount of memory that can be observed within the VM as belonging to a" + - " single NUMA node.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxMemoryBlocksPerNumaNode { - get { - if ((curObj["MaxMemoryBlocksPerNumaNode"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxMemoryBlocksPerNumaNode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherResourceType { - get { - return ((string)(curObj["OtherResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PoolID { - get { - return ((string)(curObj["PoolID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReservationNull { - get { - if ((curObj["Reservation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Reservation { - get { - if ((curObj["Reservation"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Reservation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ResourceSubType { - get { - return ((string)(curObj["ResourceSubType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResourceTypeNull { - get { - if ((curObj["ResourceType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResourceType { - get { - if ((curObj["ResourceType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResourceType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSwapFilesInUseNull { - get { - if ((curObj["SwapFilesInUse"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates if smart paging is active.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool SwapFilesInUse { - get { - if ((curObj["SwapFilesInUse"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["SwapFilesInUse"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTargetMemoryBufferNull { - get { - if ((curObj["TargetMemoryBuffer"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint TargetMemoryBuffer { - get { - if ((curObj["TargetMemoryBuffer"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["TargetMemoryBuffer"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualQuantityNull { - get { - if ((curObj["VirtualQuantity"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualQuantity { - get { - if ((curObj["VirtualQuantity"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualQuantity"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualQuantityUnits { - get { - return ((string)(curObj["VirtualQuantityUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsWeightNull { - get { - if ((curObj["Weight"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Weight { - get { - if ((curObj["Weight"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Weight"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAutomaticAllocation() { - if ((this.IsAutomaticAllocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticDeallocation() { - if ((this.IsAutomaticDeallocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConsumerVisibility() { - if ((this.IsConsumerVisibilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDynamicMemoryEnabled() { - if ((this.IsDynamicMemoryEnabledNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeIsVirtualized() { - if ((this.IsIsVirtualizedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimit() { - if ((this.IsLimitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMappingBehavior() { - if ((this.IsMappingBehaviorNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxMemoryBlocksPerNumaNode() { - if ((this.IsMaxMemoryBlocksPerNumaNodeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReservation() { - if ((this.IsReservationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResourceType() { - if ((this.IsResourceTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeSwapFilesInUse() { - if ((this.IsSwapFilesInUseNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTargetMemoryBuffer() { - if ((this.IsTargetMemoryBufferNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualQuantity() { - if ((this.IsVirtualQuantityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeWeight() { - if ((this.IsWeightNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_MemorySettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static MemorySettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static MemorySettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static MemorySettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static MemorySettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_MemorySettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new MemorySettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_MemorySettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new MemorySettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static MemorySettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new MemorySettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class MemorySettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public MemorySettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new MemorySettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new MemorySettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class MemorySettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public MemorySettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new MemorySettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_MemorySettingData + public class MemorySettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_MemorySettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public MemorySettingData() { + this.InitializeObject(null, null, null); + } + + public MemorySettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(MemorySettingData.ConstructPath(keyInstanceID)), null); + } + + public MemorySettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(MemorySettingData.ConstructPath(keyInstanceID)), null); + } + + public MemorySettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public MemorySettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public MemorySettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public MemorySettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public MemorySettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public MemorySettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Address { + get { + return ((string)(curObj["Address"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AddressOnParent { + get { + return ((string)(curObj["AddressOnParent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AllocationUnits { + get { + return ((string)(curObj["AllocationUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticAllocationNull { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticAllocation { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticAllocation"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticDeallocationNull { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticDeallocation { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticDeallocation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Connection { + get { + return ((string[])(curObj["Connection"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConsumerVisibilityNull { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ConsumerVisibility { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ConsumerVisibility"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDynamicMemoryEnabledNull { + get { + if ((curObj["DynamicMemoryEnabled"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates if dynamic memory is enabled.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool DynamicMemoryEnabled { + get { + if ((curObj["DynamicMemoryEnabled"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["DynamicMemoryEnabled"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] HostResource { + get { + return ((string[])(curObj["HostResource"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsIsVirtualizedNull { + get { + if ((curObj["IsVirtualized"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"Indicates whether this device is virtualized or passed through, possibly using partitioning. When set to False, the underlying or host resource is utilized. At least one item shall be present in the DeviceID property. When set to True, the resource is virtualized and may not map directly to an underlying/host resource. Some implementations may support specific assignment for virtualized resources, in which case the host resource(s) are exposed using the DeviceID property. This property is always set to True.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool IsVirtualized { + get { + if ((curObj["IsVirtualized"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["IsVirtualized"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitNull { + get { + if ((curObj["Limit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Limit { + get { + if ((curObj["Limit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Limit"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMappingBehaviorNull { + get { + if ((curObj["MappingBehavior"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort MappingBehavior { + get { + if ((curObj["MappingBehavior"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["MappingBehavior"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxMemoryBlocksPerNumaNodeNull { + get { + if ((curObj["MaxMemoryBlocksPerNumaNode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum amount of memory that can be observed within the VM as belonging to a" + + " single NUMA node.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxMemoryBlocksPerNumaNode { + get { + if ((curObj["MaxMemoryBlocksPerNumaNode"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxMemoryBlocksPerNumaNode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherResourceType { + get { + return ((string)(curObj["OtherResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PoolID { + get { + return ((string)(curObj["PoolID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReservationNull { + get { + if ((curObj["Reservation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Reservation { + get { + if ((curObj["Reservation"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Reservation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ResourceSubType { + get { + return ((string)(curObj["ResourceSubType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResourceTypeNull { + get { + if ((curObj["ResourceType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResourceType { + get { + if ((curObj["ResourceType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResourceType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSwapFilesInUseNull { + get { + if ((curObj["SwapFilesInUse"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates if smart paging is active.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool SwapFilesInUse { + get { + if ((curObj["SwapFilesInUse"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["SwapFilesInUse"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTargetMemoryBufferNull { + get { + if ((curObj["TargetMemoryBuffer"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint TargetMemoryBuffer { + get { + if ((curObj["TargetMemoryBuffer"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["TargetMemoryBuffer"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualQuantityNull { + get { + if ((curObj["VirtualQuantity"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualQuantity { + get { + if ((curObj["VirtualQuantity"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualQuantity"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualQuantityUnits { + get { + return ((string)(curObj["VirtualQuantityUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsWeightNull { + get { + if ((curObj["Weight"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Weight { + get { + if ((curObj["Weight"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Weight"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAutomaticAllocation() { + if ((this.IsAutomaticAllocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticDeallocation() { + if ((this.IsAutomaticDeallocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConsumerVisibility() { + if ((this.IsConsumerVisibilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDynamicMemoryEnabled() { + if ((this.IsDynamicMemoryEnabledNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeIsVirtualized() { + if ((this.IsIsVirtualizedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimit() { + if ((this.IsLimitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMappingBehavior() { + if ((this.IsMappingBehaviorNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxMemoryBlocksPerNumaNode() { + if ((this.IsMaxMemoryBlocksPerNumaNodeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReservation() { + if ((this.IsReservationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResourceType() { + if ((this.IsResourceTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeSwapFilesInUse() { + if ((this.IsSwapFilesInUseNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTargetMemoryBuffer() { + if ((this.IsTargetMemoryBufferNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualQuantity() { + if ((this.IsVirtualQuantityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeWeight() { + if ((this.IsWeightNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_MemorySettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static MemorySettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static MemorySettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static MemorySettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static MemorySettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_MemorySettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new MemorySettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static MemorySettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_MemorySettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new MemorySettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static MemorySettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new MemorySettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class MemorySettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public MemorySettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new MemorySettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new MemorySettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class MemorySettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public MemorySettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new MemorySettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ProcessorSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ProcessorSettingData.cs index 0962e7e6f91d..f26a1f168c92 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ProcessorSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ProcessorSettingData.cs @@ -1,1134 +1,1134 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_ProcessorSettingData - public class ProcessorSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_ProcessorSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public ProcessorSettingData() { - this.InitializeObject(null, null, null); - } - - public ProcessorSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(ProcessorSettingData.ConstructPath(keyInstanceID)), null); - } - - public ProcessorSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ProcessorSettingData.ConstructPath(keyInstanceID)), null); - } - - public ProcessorSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public ProcessorSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public ProcessorSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public ProcessorSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public ProcessorSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public ProcessorSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Address { - get { - return ((string)(curObj["Address"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AddressOnParent { - get { - return ((string)(curObj["AddressOnParent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AllocationUnits { - get { - return ((string)(curObj["AllocationUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticAllocationNull { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticAllocation { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticAllocation"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticDeallocationNull { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticDeallocation { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticDeallocation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Connection { - get { - return ((string[])(curObj["Connection"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConsumerVisibilityNull { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ConsumerVisibility { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ConsumerVisibility"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] HostResource { - get { - return ((string[])(curObj["HostResource"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitNull { - get { - if ((curObj["Limit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Limit { - get { - if ((curObj["Limit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Limit"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitCPUIDNull { - get { - if ((curObj["LimitCPUID"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates whether the virtual machine should lower the CPU identifier. Some older" + - " operating systems may require you to limit processor functionality in this way " + - "in order to run.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool LimitCPUID { - get { - if ((curObj["LimitCPUID"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["LimitCPUID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitProcessorFeaturesNull { - get { - if ((curObj["LimitProcessorFeatures"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"Indicates whether the VM should limit the CPU features exposed to the operating system. Limiting the processor features enables the VM to be migrated to different host computer systems with different processors. Migrating VMs between computers with processors from different vendors is not supported.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool LimitProcessorFeatures { - get { - if ((curObj["LimitProcessorFeatures"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["LimitProcessorFeatures"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMappingBehaviorNull { - get { - if ((curObj["MappingBehavior"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort MappingBehavior { - get { - if ((curObj["MappingBehavior"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["MappingBehavior"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxNumaNodesPerSocketNull { - get { - if ((curObj["MaxNumaNodesPerSocket"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum number of NUMA nodes that can be observed within the VM as belonging " + - "to a single processor socket.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxNumaNodesPerSocket { - get { - if ((curObj["MaxNumaNodesPerSocket"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxNumaNodesPerSocket"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxProcessorsPerNumaNodeNull { - get { - if ((curObj["MaxProcessorsPerNumaNode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum number of virtual processors that can be observed within the VM as be" + - "longing to a single virtual NUMA node.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxProcessorsPerNumaNode { - get { - if ((curObj["MaxProcessorsPerNumaNode"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxProcessorsPerNumaNode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherResourceType { - get { - return ((string)(curObj["OtherResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PoolID { - get { - return ((string)(curObj["PoolID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReservationNull { - get { - if ((curObj["Reservation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Reservation { - get { - if ((curObj["Reservation"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Reservation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ResourceSubType { - get { - return ((string)(curObj["ResourceSubType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResourceTypeNull { - get { - if ((curObj["ResourceType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResourceType { - get { - if ((curObj["ResourceType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResourceType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualQuantityNull { - get { - if ((curObj["VirtualQuantity"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualQuantity { - get { - if ((curObj["VirtualQuantity"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualQuantity"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualQuantityUnits { - get { - return ((string)(curObj["VirtualQuantityUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsWeightNull { - get { - if ((curObj["Weight"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Weight { - get { - if ((curObj["Weight"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Weight"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAutomaticAllocation() { - if ((this.IsAutomaticAllocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticDeallocation() { - if ((this.IsAutomaticDeallocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConsumerVisibility() { - if ((this.IsConsumerVisibilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimit() { - if ((this.IsLimitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimitCPUID() { - if ((this.IsLimitCPUIDNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimitProcessorFeatures() { - if ((this.IsLimitProcessorFeaturesNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMappingBehavior() { - if ((this.IsMappingBehaviorNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxNumaNodesPerSocket() { - if ((this.IsMaxNumaNodesPerSocketNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxProcessorsPerNumaNode() { - if ((this.IsMaxProcessorsPerNumaNodeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReservation() { - if ((this.IsReservationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResourceType() { - if ((this.IsResourceTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualQuantity() { - if ((this.IsVirtualQuantityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeWeight() { - if ((this.IsWeightNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_ProcessorSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static ProcessorSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static ProcessorSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static ProcessorSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static ProcessorSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_ProcessorSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new ProcessorSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ProcessorSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new ProcessorSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static ProcessorSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new ProcessorSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class ProcessorSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public ProcessorSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new ProcessorSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new ProcessorSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class ProcessorSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public ProcessorSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new ProcessorSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_ProcessorSettingData + public class ProcessorSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_ProcessorSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public ProcessorSettingData() { + this.InitializeObject(null, null, null); + } + + public ProcessorSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(ProcessorSettingData.ConstructPath(keyInstanceID)), null); + } + + public ProcessorSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ProcessorSettingData.ConstructPath(keyInstanceID)), null); + } + + public ProcessorSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public ProcessorSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public ProcessorSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public ProcessorSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public ProcessorSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public ProcessorSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Address { + get { + return ((string)(curObj["Address"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AddressOnParent { + get { + return ((string)(curObj["AddressOnParent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AllocationUnits { + get { + return ((string)(curObj["AllocationUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticAllocationNull { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticAllocation { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticAllocation"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticDeallocationNull { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticDeallocation { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticDeallocation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Connection { + get { + return ((string[])(curObj["Connection"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConsumerVisibilityNull { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ConsumerVisibility { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ConsumerVisibility"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] HostResource { + get { + return ((string[])(curObj["HostResource"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitNull { + get { + if ((curObj["Limit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Limit { + get { + if ((curObj["Limit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Limit"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitCPUIDNull { + get { + if ((curObj["LimitCPUID"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates whether the virtual machine should lower the CPU identifier. Some older" + + " operating systems may require you to limit processor functionality in this way " + + "in order to run.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool LimitCPUID { + get { + if ((curObj["LimitCPUID"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["LimitCPUID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitProcessorFeaturesNull { + get { + if ((curObj["LimitProcessorFeatures"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"Indicates whether the VM should limit the CPU features exposed to the operating system. Limiting the processor features enables the VM to be migrated to different host computer systems with different processors. Migrating VMs between computers with processors from different vendors is not supported.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool LimitProcessorFeatures { + get { + if ((curObj["LimitProcessorFeatures"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["LimitProcessorFeatures"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMappingBehaviorNull { + get { + if ((curObj["MappingBehavior"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort MappingBehavior { + get { + if ((curObj["MappingBehavior"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["MappingBehavior"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxNumaNodesPerSocketNull { + get { + if ((curObj["MaxNumaNodesPerSocket"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum number of NUMA nodes that can be observed within the VM as belonging " + + "to a single processor socket.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxNumaNodesPerSocket { + get { + if ((curObj["MaxNumaNodesPerSocket"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxNumaNodesPerSocket"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxProcessorsPerNumaNodeNull { + get { + if ((curObj["MaxProcessorsPerNumaNode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum number of virtual processors that can be observed within the VM as be" + + "longing to a single virtual NUMA node.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxProcessorsPerNumaNode { + get { + if ((curObj["MaxProcessorsPerNumaNode"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxProcessorsPerNumaNode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherResourceType { + get { + return ((string)(curObj["OtherResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PoolID { + get { + return ((string)(curObj["PoolID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReservationNull { + get { + if ((curObj["Reservation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Reservation { + get { + if ((curObj["Reservation"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Reservation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ResourceSubType { + get { + return ((string)(curObj["ResourceSubType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResourceTypeNull { + get { + if ((curObj["ResourceType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResourceType { + get { + if ((curObj["ResourceType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResourceType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualQuantityNull { + get { + if ((curObj["VirtualQuantity"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualQuantity { + get { + if ((curObj["VirtualQuantity"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualQuantity"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualQuantityUnits { + get { + return ((string)(curObj["VirtualQuantityUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsWeightNull { + get { + if ((curObj["Weight"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Weight { + get { + if ((curObj["Weight"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Weight"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAutomaticAllocation() { + if ((this.IsAutomaticAllocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticDeallocation() { + if ((this.IsAutomaticDeallocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConsumerVisibility() { + if ((this.IsConsumerVisibilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimit() { + if ((this.IsLimitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimitCPUID() { + if ((this.IsLimitCPUIDNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimitProcessorFeatures() { + if ((this.IsLimitProcessorFeaturesNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMappingBehavior() { + if ((this.IsMappingBehaviorNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxNumaNodesPerSocket() { + if ((this.IsMaxNumaNodesPerSocketNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxProcessorsPerNumaNode() { + if ((this.IsMaxProcessorsPerNumaNodeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReservation() { + if ((this.IsReservationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResourceType() { + if ((this.IsResourceTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualQuantity() { + if ((this.IsVirtualQuantityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeWeight() { + if ((this.IsWeightNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_ProcessorSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static ProcessorSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static ProcessorSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static ProcessorSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static ProcessorSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_ProcessorSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new ProcessorSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static ProcessorSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ProcessorSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new ProcessorSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static ProcessorSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new ProcessorSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class ProcessorSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public ProcessorSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new ProcessorSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new ProcessorSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class ProcessorSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public ProcessorSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new ProcessorSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ResourceAllocationSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ResourceAllocationSettingData.cs index de4ce9320fb3..18483c718938 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ResourceAllocationSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_ResourceAllocationSettingData.cs @@ -1,1010 +1,1010 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 -{ - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_ResourceAllocationSettingData - public class ResourceAllocationSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_ResourceAllocationSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public ResourceAllocationSettingData() { - this.InitializeObject(null, null, null); - } - - public ResourceAllocationSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(ResourceAllocationSettingData.ConstructPath(keyInstanceID)), null); - } - - public ResourceAllocationSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ResourceAllocationSettingData.ConstructPath(keyInstanceID)), null); - } - - public ResourceAllocationSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public ResourceAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public ResourceAllocationSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public ResourceAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public ResourceAllocationSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public ResourceAllocationSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Address { - get { - return ((string)(curObj["Address"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AddressOnParent { - get { - return ((string)(curObj["AddressOnParent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AllocationUnits { - get { - return ((string)(curObj["AllocationUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticAllocationNull { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticAllocation { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticAllocation"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticDeallocationNull { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticDeallocation { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticDeallocation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Connection { - get { - return ((string[])(curObj["Connection"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConsumerVisibilityNull { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ConsumerVisibility { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ConsumerVisibility"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] HostResource { - get { - return ((string[])(curObj["HostResource"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitNull { - get { - if ((curObj["Limit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Limit { - get { - if ((curObj["Limit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Limit"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMappingBehaviorNull { - get { - if ((curObj["MappingBehavior"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort MappingBehavior { - get { - if ((curObj["MappingBehavior"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["MappingBehavior"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherResourceType { - get { - return ((string)(curObj["OtherResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PoolID { - get { - return ((string)(curObj["PoolID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReservationNull { - get { - if ((curObj["Reservation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Reservation { - get { - if ((curObj["Reservation"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Reservation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ResourceSubType { - get { - return ((string)(curObj["ResourceSubType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResourceTypeNull { - get { - if ((curObj["ResourceType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResourceType { - get { - if ((curObj["ResourceType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResourceType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualQuantityNull { - get { - if ((curObj["VirtualQuantity"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualQuantity { - get { - if ((curObj["VirtualQuantity"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualQuantity"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualQuantityUnits { - get { - return ((string)(curObj["VirtualQuantityUnits"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"A free-form string array of identifiers of this resource presented to the virtual computer system's operating system. These values are only used if the ResourceType property is set to 6 (Parallel SCSI HBA) and the ResourceSubType property is set to ""Microsoft Synthetic SCSI Controller"". This property is set to ""GUID"". -This is a read-only property, but it can be changed using the ModifyVirtualSystemResources method of the Msvm_VirtualSystemManagementService class. -Windows Server 2008: The VirtualSystemIdentifiers property is not supported until Windows Server 2008 R2.")] - public string[] VirtualSystemIdentifiers { - get { - return ((string[])(curObj["VirtualSystemIdentifiers"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsWeightNull { - get { - if ((curObj["Weight"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Weight { - get { - if ((curObj["Weight"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Weight"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAutomaticAllocation() { - if ((this.IsAutomaticAllocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticDeallocation() { - if ((this.IsAutomaticDeallocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConsumerVisibility() { - if ((this.IsConsumerVisibilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimit() { - if ((this.IsLimitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMappingBehavior() { - if ((this.IsMappingBehaviorNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReservation() { - if ((this.IsReservationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResourceType() { - if ((this.IsResourceTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualQuantity() { - if ((this.IsVirtualQuantityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeWeight() { - if ((this.IsWeightNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_ResourceAllocationSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static ResourceAllocationSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static ResourceAllocationSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static ResourceAllocationSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static ResourceAllocationSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_ResourceAllocationSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new ResourceAllocationSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ResourceAllocationSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new ResourceAllocationSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static ResourceAllocationSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new ResourceAllocationSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class ResourceAllocationSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public ResourceAllocationSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new ResourceAllocationSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new ResourceAllocationSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class ResourceAllocationSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public ResourceAllocationSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new ResourceAllocationSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 +{ + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_ResourceAllocationSettingData + public class ResourceAllocationSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_ResourceAllocationSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public ResourceAllocationSettingData() { + this.InitializeObject(null, null, null); + } + + public ResourceAllocationSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(ResourceAllocationSettingData.ConstructPath(keyInstanceID)), null); + } + + public ResourceAllocationSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(ResourceAllocationSettingData.ConstructPath(keyInstanceID)), null); + } + + public ResourceAllocationSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public ResourceAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public ResourceAllocationSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public ResourceAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public ResourceAllocationSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public ResourceAllocationSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Address { + get { + return ((string)(curObj["Address"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AddressOnParent { + get { + return ((string)(curObj["AddressOnParent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AllocationUnits { + get { + return ((string)(curObj["AllocationUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticAllocationNull { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticAllocation { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticAllocation"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticDeallocationNull { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticDeallocation { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticDeallocation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Connection { + get { + return ((string[])(curObj["Connection"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConsumerVisibilityNull { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ConsumerVisibility { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ConsumerVisibility"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] HostResource { + get { + return ((string[])(curObj["HostResource"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitNull { + get { + if ((curObj["Limit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Limit { + get { + if ((curObj["Limit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Limit"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMappingBehaviorNull { + get { + if ((curObj["MappingBehavior"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort MappingBehavior { + get { + if ((curObj["MappingBehavior"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["MappingBehavior"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherResourceType { + get { + return ((string)(curObj["OtherResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PoolID { + get { + return ((string)(curObj["PoolID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReservationNull { + get { + if ((curObj["Reservation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Reservation { + get { + if ((curObj["Reservation"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Reservation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ResourceSubType { + get { + return ((string)(curObj["ResourceSubType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResourceTypeNull { + get { + if ((curObj["ResourceType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResourceType { + get { + if ((curObj["ResourceType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResourceType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualQuantityNull { + get { + if ((curObj["VirtualQuantity"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualQuantity { + get { + if ((curObj["VirtualQuantity"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualQuantity"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualQuantityUnits { + get { + return ((string)(curObj["VirtualQuantityUnits"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"A free-form string array of identifiers of this resource presented to the virtual computer system's operating system. These values are only used if the ResourceType property is set to 6 (Parallel SCSI HBA) and the ResourceSubType property is set to ""Microsoft Synthetic SCSI Controller"". This property is set to ""GUID"". +This is a read-only property, but it can be changed using the ModifyVirtualSystemResources method of the Msvm_VirtualSystemManagementService class. +Windows Server 2008: The VirtualSystemIdentifiers property is not supported until Windows Server 2008 R2.")] + public string[] VirtualSystemIdentifiers { + get { + return ((string[])(curObj["VirtualSystemIdentifiers"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsWeightNull { + get { + if ((curObj["Weight"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Weight { + get { + if ((curObj["Weight"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Weight"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAutomaticAllocation() { + if ((this.IsAutomaticAllocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticDeallocation() { + if ((this.IsAutomaticDeallocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConsumerVisibility() { + if ((this.IsConsumerVisibilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimit() { + if ((this.IsLimitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMappingBehavior() { + if ((this.IsMappingBehaviorNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReservation() { + if ((this.IsReservationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResourceType() { + if ((this.IsResourceTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualQuantity() { + if ((this.IsVirtualQuantityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeWeight() { + if ((this.IsWeightNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_ResourceAllocationSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static ResourceAllocationSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static ResourceAllocationSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static ResourceAllocationSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static ResourceAllocationSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_ResourceAllocationSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new ResourceAllocationSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static ResourceAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_ResourceAllocationSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new ResourceAllocationSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static ResourceAllocationSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new ResourceAllocationSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class ResourceAllocationSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public ResourceAllocationSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new ResourceAllocationSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new ResourceAllocationSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class ResourceAllocationSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public ResourceAllocationSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new ResourceAllocationSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_StorageAllocationSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_StorageAllocationSettingData.cs index 45f6b06ae4a5..b24d2cfcc269 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_StorageAllocationSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_StorageAllocationSettingData.cs @@ -1,1214 +1,1214 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_StorageAllocationSettingData - public class StorageAllocationSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_StorageAllocationSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public StorageAllocationSettingData() { - this.InitializeObject(null, null, null); - } - - public StorageAllocationSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(StorageAllocationSettingData.ConstructPath(keyInstanceID)), null); - } - - public StorageAllocationSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(StorageAllocationSettingData.ConstructPath(keyInstanceID)), null); - } - - public StorageAllocationSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public StorageAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public StorageAllocationSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public StorageAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public StorageAllocationSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public StorageAllocationSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAccessNull { - get { - if ((curObj["Access"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort Access { - get { - if ((curObj["Access"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["Access"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Address { - get { - return ((string)(curObj["Address"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AddressOnParent { - get { - return ((string)(curObj["AddressOnParent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AllocationUnits { - get { - return ((string)(curObj["AllocationUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticAllocationNull { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticAllocation { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticAllocation"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticDeallocationNull { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticDeallocation { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticDeallocation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Connection { - get { - return ((string[])(curObj["Connection"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConsumerVisibilityNull { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ConsumerVisibility { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ConsumerVisibility"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string HostExtentName { - get { - return ((string)(curObj["HostExtentName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHostExtentNameFormatNull { - get { - if ((curObj["HostExtentNameFormat"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HostExtentNameFormat { - get { - if ((curObj["HostExtentNameFormat"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HostExtentNameFormat"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHostExtentNameNamespaceNull { - get { - if ((curObj["HostExtentNameNamespace"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HostExtentNameNamespace { - get { - if ((curObj["HostExtentNameNamespace"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HostExtentNameNamespace"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHostExtentStartingAddressNull { - get { - if ((curObj["HostExtentStartingAddress"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong HostExtentStartingAddress { - get { - if ((curObj["HostExtentStartingAddress"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["HostExtentStartingAddress"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] HostResource { - get { - return ((string[])(curObj["HostResource"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHostResourceBlockSizeNull { - get { - if ((curObj["HostResourceBlockSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong HostResourceBlockSize { - get { - if ((curObj["HostResourceBlockSize"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["HostResourceBlockSize"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitNull { - get { - if ((curObj["Limit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Limit { - get { - if ((curObj["Limit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Limit"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMappingBehaviorNull { - get { - if ((curObj["MappingBehavior"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort MappingBehavior { - get { - if ((curObj["MappingBehavior"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["MappingBehavior"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherHostExtentNameFormat { - get { - return ((string)(curObj["OtherHostExtentNameFormat"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherHostExtentNameNamespace { - get { - return ((string)(curObj["OtherHostExtentNameNamespace"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherResourceType { - get { - return ((string)(curObj["OtherResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PoolID { - get { - return ((string)(curObj["PoolID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReservationNull { - get { - if ((curObj["Reservation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Reservation { - get { - if ((curObj["Reservation"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Reservation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ResourceSubType { - get { - return ((string)(curObj["ResourceSubType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResourceTypeNull { - get { - if ((curObj["ResourceType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResourceType { - get { - if ((curObj["ResourceType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResourceType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualQuantityNull { - get { - if ((curObj["VirtualQuantity"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualQuantity { - get { - if ((curObj["VirtualQuantity"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualQuantity"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualQuantityUnits { - get { - return ((string)(curObj["VirtualQuantityUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualResourceBlockSizeNull { - get { - if ((curObj["VirtualResourceBlockSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualResourceBlockSize { - get { - if ((curObj["VirtualResourceBlockSize"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualResourceBlockSize"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsWeightNull { - get { - if ((curObj["Weight"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Weight { - get { - if ((curObj["Weight"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Weight"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAccess() { - if ((this.IsAccessNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticAllocation() { - if ((this.IsAutomaticAllocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticDeallocation() { - if ((this.IsAutomaticDeallocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConsumerVisibility() { - if ((this.IsConsumerVisibilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHostExtentNameFormat() { - if ((this.IsHostExtentNameFormatNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHostExtentNameNamespace() { - if ((this.IsHostExtentNameNamespaceNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHostExtentStartingAddress() { - if ((this.IsHostExtentStartingAddressNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHostResourceBlockSize() { - if ((this.IsHostResourceBlockSizeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimit() { - if ((this.IsLimitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMappingBehavior() { - if ((this.IsMappingBehaviorNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReservation() { - if ((this.IsReservationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResourceType() { - if ((this.IsResourceTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualQuantity() { - if ((this.IsVirtualQuantityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualResourceBlockSize() { - if ((this.IsVirtualResourceBlockSizeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeWeight() { - if ((this.IsWeightNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_StorageAllocationSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static StorageAllocationSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static StorageAllocationSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static StorageAllocationSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static StorageAllocationSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_StorageAllocationSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new StorageAllocationSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_StorageAllocationSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new StorageAllocationSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static StorageAllocationSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new StorageAllocationSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class StorageAllocationSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public StorageAllocationSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new StorageAllocationSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new StorageAllocationSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class StorageAllocationSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public StorageAllocationSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new StorageAllocationSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_StorageAllocationSettingData + public class StorageAllocationSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_StorageAllocationSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public StorageAllocationSettingData() { + this.InitializeObject(null, null, null); + } + + public StorageAllocationSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(StorageAllocationSettingData.ConstructPath(keyInstanceID)), null); + } + + public StorageAllocationSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(StorageAllocationSettingData.ConstructPath(keyInstanceID)), null); + } + + public StorageAllocationSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public StorageAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public StorageAllocationSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public StorageAllocationSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public StorageAllocationSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public StorageAllocationSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAccessNull { + get { + if ((curObj["Access"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort Access { + get { + if ((curObj["Access"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["Access"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Address { + get { + return ((string)(curObj["Address"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AddressOnParent { + get { + return ((string)(curObj["AddressOnParent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AllocationUnits { + get { + return ((string)(curObj["AllocationUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticAllocationNull { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticAllocation { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticAllocation"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticDeallocationNull { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticDeallocation { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticDeallocation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Connection { + get { + return ((string[])(curObj["Connection"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConsumerVisibilityNull { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ConsumerVisibility { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ConsumerVisibility"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string HostExtentName { + get { + return ((string)(curObj["HostExtentName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHostExtentNameFormatNull { + get { + if ((curObj["HostExtentNameFormat"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HostExtentNameFormat { + get { + if ((curObj["HostExtentNameFormat"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HostExtentNameFormat"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHostExtentNameNamespaceNull { + get { + if ((curObj["HostExtentNameNamespace"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HostExtentNameNamespace { + get { + if ((curObj["HostExtentNameNamespace"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HostExtentNameNamespace"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHostExtentStartingAddressNull { + get { + if ((curObj["HostExtentStartingAddress"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong HostExtentStartingAddress { + get { + if ((curObj["HostExtentStartingAddress"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["HostExtentStartingAddress"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] HostResource { + get { + return ((string[])(curObj["HostResource"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHostResourceBlockSizeNull { + get { + if ((curObj["HostResourceBlockSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong HostResourceBlockSize { + get { + if ((curObj["HostResourceBlockSize"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["HostResourceBlockSize"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitNull { + get { + if ((curObj["Limit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Limit { + get { + if ((curObj["Limit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Limit"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMappingBehaviorNull { + get { + if ((curObj["MappingBehavior"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort MappingBehavior { + get { + if ((curObj["MappingBehavior"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["MappingBehavior"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherHostExtentNameFormat { + get { + return ((string)(curObj["OtherHostExtentNameFormat"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherHostExtentNameNamespace { + get { + return ((string)(curObj["OtherHostExtentNameNamespace"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherResourceType { + get { + return ((string)(curObj["OtherResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PoolID { + get { + return ((string)(curObj["PoolID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReservationNull { + get { + if ((curObj["Reservation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Reservation { + get { + if ((curObj["Reservation"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Reservation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ResourceSubType { + get { + return ((string)(curObj["ResourceSubType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResourceTypeNull { + get { + if ((curObj["ResourceType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResourceType { + get { + if ((curObj["ResourceType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResourceType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualQuantityNull { + get { + if ((curObj["VirtualQuantity"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualQuantity { + get { + if ((curObj["VirtualQuantity"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualQuantity"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualQuantityUnits { + get { + return ((string)(curObj["VirtualQuantityUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualResourceBlockSizeNull { + get { + if ((curObj["VirtualResourceBlockSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualResourceBlockSize { + get { + if ((curObj["VirtualResourceBlockSize"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualResourceBlockSize"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsWeightNull { + get { + if ((curObj["Weight"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Weight { + get { + if ((curObj["Weight"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Weight"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAccess() { + if ((this.IsAccessNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticAllocation() { + if ((this.IsAutomaticAllocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticDeallocation() { + if ((this.IsAutomaticDeallocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConsumerVisibility() { + if ((this.IsConsumerVisibilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHostExtentNameFormat() { + if ((this.IsHostExtentNameFormatNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHostExtentNameNamespace() { + if ((this.IsHostExtentNameNamespaceNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHostExtentStartingAddress() { + if ((this.IsHostExtentStartingAddressNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHostResourceBlockSize() { + if ((this.IsHostResourceBlockSizeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimit() { + if ((this.IsLimitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMappingBehavior() { + if ((this.IsMappingBehaviorNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReservation() { + if ((this.IsReservationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResourceType() { + if ((this.IsResourceTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualQuantity() { + if ((this.IsVirtualQuantityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualResourceBlockSize() { + if ((this.IsVirtualResourceBlockSizeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeWeight() { + if ((this.IsWeightNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_StorageAllocationSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static StorageAllocationSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static StorageAllocationSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static StorageAllocationSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static StorageAllocationSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_StorageAllocationSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new StorageAllocationSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static StorageAllocationSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_StorageAllocationSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new StorageAllocationSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static StorageAllocationSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new StorageAllocationSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class StorageAllocationSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public StorageAllocationSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new StorageAllocationSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new StorageAllocationSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class StorageAllocationSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public StorageAllocationSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new StorageAllocationSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SummaryInformation.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SummaryInformation.cs index 604005be2ff8..343f4122eb0f 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SummaryInformation.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SummaryInformation.cs @@ -1,1537 +1,1537 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // - // - // - // - // If the embedded property is strongly typed then, to strongly type the property to the type of - // the embedded object, you have to do the following things. - // 1. Generate Managed class for the WMI class of the embedded property. This can be done with MgmtClassGen.exe tool or from Server Explorer. - // 2. Include the namespace of the generated class. - // 3. Change the property get/set functions so as return the instance of the Managed class. - // Below is a sample code. - // - // VB Code - // - // - // - // Property name - // Managed class name of Embedded Property - // - // - // - // - // - // - // C# Code - // - // - // - // Managed class name of Embedded property - // Property name - // - // - // - // - // - // - // - // - // - // - // An Early Bound class generated for the WMI class.Msvm_SummaryInformation - public class SummaryInformation : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_SummaryInformation"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public SummaryInformation() { - this.InitializeObject(null, null, null); - } - - public SummaryInformation(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public SummaryInformation(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public SummaryInformation(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public SummaryInformation(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public SummaryInformation(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public SummaryInformation(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The identifier of the physical graphics processing unit (GPU) allocated to this v" + - "irtual machine (VM). This property only applies to VMs that use RemoteFX.")] - public string AllocatedGPU { - get { - return ((string)(curObj["AllocatedGPU"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsApplicationHealthNull { - get { - if ((curObj["ApplicationHealth"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"The current application health status for the virtual system. This property may be one of the following values: ""OK""; ""Application Critical""; ""Disabled"".For more information, see the documentation for the StatusDescriptions property of the Msvm_HeartbeatComponent class. This property is not valid for instances of Msvm_SummaryInformation representing a virtual system snapshot.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ApplicationHealthValues ApplicationHealth { - get { - if ((curObj["ApplicationHealth"] == null)) { - return ((ApplicationHealthValues)(System.Convert.ToInt32(0))); - } - return ((ApplicationHealthValues)(System.Convert.ToInt32(curObj["ApplicationHealth"]))); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("An array of Msvm_ConcreteJob instances representing any asynchronous operations r" + - "elated to the virtual system which are currently executing. This property is not" + - " valid for instances of Msvm_SummaryInformation representing a virtual system sn" + - "apshot.")] - public System.Management.ManagementBaseObject[] AsynchronousTasks { - get { - return ((System.Management.ManagementBaseObject[])(curObj["AsynchronousTasks"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAvailableMemoryBufferNull { - get { - if ((curObj["AvailableMemoryBuffer"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The available memory buffer percentage in the virtual system.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public int AvailableMemoryBuffer { - get { - if ((curObj["AvailableMemoryBuffer"] == null)) { - return System.Convert.ToInt32(0); - } - return ((int)(curObj["AvailableMemoryBuffer"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCreationTimeNull { - get { - if ((curObj["CreationTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The time at which the virtual system or snapshot was created.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime CreationTime { - get { - if ((curObj["CreationTime"] != null)) { - return ToDateTime(((string)(curObj["CreationTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The friendly name for the virtual system or snapshot.")] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The current state of the virtual system or snapshot.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The name of the guest operating system, if available. If this information is not " + - "available, the value of this property is NULL. This property is not valid for in" + - "stances of Msvm_SummaryInformation representing a virtual system snapshot.")] - public string GuestOperatingSystem { - get { - return ((string)(curObj["GuestOperatingSystem"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The current health state for the virtual system. This property is not valid for i" + - "nstances of Msvm_SummaryInformation representing a virtual system snapshot.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHeartbeatNull { - get { - if ((curObj["Heartbeat"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"The current heartbeat status for the virtual system. This property may be one of the following values: ""OK""; ""Error""; ""No Contact""; or ""Lost Communication"". For more information, see the documentation for the StatusDescriptions property of the Msvm_HeartbeatComponent class. This property is not valid for instances of Msvm_SummaryInformation representing a virtual system snapshot.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort Heartbeat { - get { - if ((curObj["Heartbeat"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["Heartbeat"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsIntegrationServicesVersionStateNull { - get { - if ((curObj["IntegrationServicesVersionState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Whether or not the integration services installed in the virtual machine are up t" + - "o date")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public IntegrationServicesVersionStateValues IntegrationServicesVersionState { - get { - if ((curObj["IntegrationServicesVersionState"] == null)) { - return ((IntegrationServicesVersionStateValues)(System.Convert.ToInt32(3))); - } - return ((IntegrationServicesVersionStateValues)(System.Convert.ToInt32(curObj["IntegrationServicesVersionState"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMemoryAvailableNull { - get { - if ((curObj["MemoryAvailable"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The memory available percentage in the virtual system.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public int MemoryAvailable { - get { - if ((curObj["MemoryAvailable"] == null)) { - return System.Convert.ToInt32(0); - } - return ((int)(curObj["MemoryAvailable"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMemorySpansPhysicalNumaNodesNull { - get { - if ((curObj["MemorySpansPhysicalNumaNodes"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates whether or not the memory of the one or more of the virtual non-uniform" + - " memory access (NUMA) nodes of the virtual machine spans multiple physical NUMA " + - "nodes of the hosting computer system.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool MemorySpansPhysicalNumaNodes { - get { - if ((curObj["MemorySpansPhysicalNumaNodes"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["MemorySpansPhysicalNumaNodes"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMemoryUsageNull { - get { - if ((curObj["MemoryUsage"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The current memory usage of the virtual system. This property is not valid for in" + - "stances of Msvm_SummaryInformation representing a virtual system snapshot.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MemoryUsage { - get { - if ((curObj["MemoryUsage"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MemoryUsage"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The unique name for the virtual system or snapshot.")] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The notes associated with the virtual system or snapshot.")] - public string Notes { - get { - return ((string)(curObj["Notes"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsNumberOfProcessorsNull { - get { - if ((curObj["NumberOfProcessors"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The total number of virtual processors allocated to the virtual system or snapsho" + - "t.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort NumberOfProcessors { - get { - if ((curObj["NumberOfProcessors"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["NumberOfProcessors"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The current status of the element.")] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("A string that describes the enabled or disabled state of the element when the Ena" + - "bledState property is set to 1 (\"Other\"). This property must be set to null when" + - " EnabledState is any value other than 1.")] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsProcessorLoadNull { - get { - if ((curObj["ProcessorLoad"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The current processor usage of the virtual system. This property is not valid for" + - " instances of Msvm_SummaryInformation representing a virtual system snapshot.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ProcessorLoad { - get { - if ((curObj["ProcessorLoad"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ProcessorLoad"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("An array of the previous 100 samples of the processor usage for the virtual syste" + - "m. This property is not valid for instances of Msvm_SummaryInformation represent" + - "ing a virtual system snapshot.")] - public ushort[] ProcessorLoadHistory { - get { - return ((ushort[])(curObj["ProcessorLoadHistory"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReplicationHealthNull { - get { - if ((curObj["ReplicationHealth"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Replication health for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ReplicationHealthValues ReplicationHealth { - get { - if ((curObj["ReplicationHealth"] == null)) { - return ((ReplicationHealthValues)(System.Convert.ToInt32(4))); - } - return ((ReplicationHealthValues)(System.Convert.ToInt32(curObj["ReplicationHealth"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReplicationModeNull { - get { - if ((curObj["ReplicationMode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Identifies replication type for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ReplicationModeValues ReplicationMode { - get { - if ((curObj["ReplicationMode"] == null)) { - return ((ReplicationModeValues)(System.Convert.ToInt32(4))); - } - return ((ReplicationModeValues)(System.Convert.ToInt32(curObj["ReplicationMode"]))); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReplicationStateNull { - get { - if ((curObj["ReplicationState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Replication state for the virtual machine.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ReplicationStateValues ReplicationState { - get { - if ((curObj["ReplicationState"] == null)) { - return ((ReplicationStateValues)(System.Convert.ToInt32(12))); - } - return ((ReplicationStateValues)(System.Convert.ToInt32(curObj["ReplicationState"]))); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("An array of Msvm_VirtualSystemSettingData instances representing the snapshots fo" + - "r the virtual system. This property is not valid for instances of Msvm_SummaryIn" + - "formation representing a virtual system snapshot.")] - public System.Management.ManagementBaseObject[] Snapshots { - get { - return ((System.Management.ManagementBaseObject[])(curObj["Snapshots"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Strings that describe the various OperationalStatus array values.")] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsSwapFilesInUseNull { - get { - if ((curObj["SwapFilesInUse"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indecates if smart paging is active.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool SwapFilesInUse { - get { - if ((curObj["SwapFilesInUse"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["SwapFilesInUse"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Reference to the CIM_ComputerSystem instance representing the test replica virtua" + - "l system for the virtual machine. This property is not valid for instances of Ms" + - "vm_SummaryInformation representing a virtual system snapshot.")] - public System.Management.ManagementPath TestReplicaSystem { - get { - if ((curObj["TestReplicaSystem"] != null)) { - return new System.Management.ManagementPath(curObj["TestReplicaSystem"].ToString()); - } - return null; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("An array containing a small, thumbnail-sized image of the desktop for the virtual" + - " system or snapshot in RGB565 format.")] - public byte[] ThumbnailImage { - get { - return ((byte[])(curObj["ThumbnailImage"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsUpTimeNull { - get { - if ((curObj["UpTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The amount of time since the virtual system was last booted. This property is not" + - " valid for instances of Msvm_SummaryInformation representing a virtual system sn" + - "apshot.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong UpTime { - get { - if ((curObj["UpTime"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["UpTime"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeApplicationHealth() { - if ((this.IsApplicationHealthNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAvailableMemoryBuffer() { - if ((this.IsAvailableMemoryBufferNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeCreationTime() { - if ((this.IsCreationTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHeartbeat() { - if ((this.IsHeartbeatNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeIntegrationServicesVersionState() { - if ((this.IsIntegrationServicesVersionStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMemoryAvailable() { - if ((this.IsMemoryAvailableNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMemorySpansPhysicalNumaNodes() { - if ((this.IsMemorySpansPhysicalNumaNodesNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMemoryUsage() { - if ((this.IsMemoryUsageNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeNumberOfProcessors() { - if ((this.IsNumberOfProcessorsNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeProcessorLoad() { - if ((this.IsProcessorLoadNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReplicationHealth() { - if ((this.IsReplicationHealthNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReplicationMode() { - if ((this.IsReplicationModeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReplicationState() { - if ((this.IsReplicationStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeSwapFilesInUse() { - if ((this.IsSwapFilesInUseNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeUpTime() { - if ((this.IsUpTimeNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath() { - string strPath = "ROOT\\virtualization\\v2:Msvm_SummaryInformation"; - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static SummaryInformationCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static SummaryInformationCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static SummaryInformationCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static SummaryInformationCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_SummaryInformation"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new SummaryInformationCollection(clsObject.GetInstances(enumOptions)); - } - - public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_SummaryInformation", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new SummaryInformationCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static SummaryInformation CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new SummaryInformation(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public enum ApplicationHealthValues { - - OK = 2, - - Application_Critical = 32782, - - Disabled = 32896, - - NULL_ENUM_VALUE = 0, - } - - public enum IntegrationServicesVersionStateValues { - - Unknown0 = 0, - - UpToDate = 1, - - Mismatch = 2, - - NULL_ENUM_VALUE = 3, - } - - public enum ReplicationHealthValues { - - Not_applicable = 0, - - Ok = 1, - - Warning = 2, - - Critical = 3, - - NULL_ENUM_VALUE = 4, - } - - public enum ReplicationModeValues { - - None = 0, - - Primary = 1, - - Recovery = 2, - - Test_Replica = 3, - - NULL_ENUM_VALUE = 4, - } - - public enum ReplicationStateValues { - - Disabled = 0, - - Ready_for_replication = 1, - - Waiting_to_complete_initial_replication = 2, - - Replicating = 3, - - Synced_replication_complete = 4, - - Recovered = 5, - - Committed = 6, - - Suspended = 7, - - Critical = 8, - - Waiting_to_start_resynchronization = 9, - - Resynchronizing = 10, - - Resynchronization_suspended = 11, - - NULL_ENUM_VALUE = 12, - } - - // Enumerator implementation for enumerating instances of the class. - public class SummaryInformationCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public SummaryInformationCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new SummaryInformation(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new SummaryInformationEnumerator(privColObj.GetEnumerator()); - } - - public class SummaryInformationEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public SummaryInformationEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new SummaryInformation(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // + // + // + // + // If the embedded property is strongly typed then, to strongly type the property to the type of + // the embedded object, you have to do the following things. + // 1. Generate Managed class for the WMI class of the embedded property. This can be done with MgmtClassGen.exe tool or from Server Explorer. + // 2. Include the namespace of the generated class. + // 3. Change the property get/set functions so as return the instance of the Managed class. + // Below is a sample code. + // + // VB Code + // + // + // + // Property name + // Managed class name of Embedded Property + // + // + // + // + // + // + // C# Code + // + // + // + // Managed class name of Embedded property + // Property name + // + // + // + // + // + // + // + // + // + // + // An Early Bound class generated for the WMI class.Msvm_SummaryInformation + public class SummaryInformation : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_SummaryInformation"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public SummaryInformation() { + this.InitializeObject(null, null, null); + } + + public SummaryInformation(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public SummaryInformation(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public SummaryInformation(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public SummaryInformation(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public SummaryInformation(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public SummaryInformation(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The identifier of the physical graphics processing unit (GPU) allocated to this v" + + "irtual machine (VM). This property only applies to VMs that use RemoteFX.")] + public string AllocatedGPU { + get { + return ((string)(curObj["AllocatedGPU"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsApplicationHealthNull { + get { + if ((curObj["ApplicationHealth"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"The current application health status for the virtual system. This property may be one of the following values: ""OK""; ""Application Critical""; ""Disabled"".For more information, see the documentation for the StatusDescriptions property of the Msvm_HeartbeatComponent class. This property is not valid for instances of Msvm_SummaryInformation representing a virtual system snapshot.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ApplicationHealthValues ApplicationHealth { + get { + if ((curObj["ApplicationHealth"] == null)) { + return ((ApplicationHealthValues)(System.Convert.ToInt32(0))); + } + return ((ApplicationHealthValues)(System.Convert.ToInt32(curObj["ApplicationHealth"]))); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("An array of Msvm_ConcreteJob instances representing any asynchronous operations r" + + "elated to the virtual system which are currently executing. This property is not" + + " valid for instances of Msvm_SummaryInformation representing a virtual system sn" + + "apshot.")] + public System.Management.ManagementBaseObject[] AsynchronousTasks { + get { + return ((System.Management.ManagementBaseObject[])(curObj["AsynchronousTasks"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAvailableMemoryBufferNull { + get { + if ((curObj["AvailableMemoryBuffer"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The available memory buffer percentage in the virtual system.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public int AvailableMemoryBuffer { + get { + if ((curObj["AvailableMemoryBuffer"] == null)) { + return System.Convert.ToInt32(0); + } + return ((int)(curObj["AvailableMemoryBuffer"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCreationTimeNull { + get { + if ((curObj["CreationTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The time at which the virtual system or snapshot was created.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime CreationTime { + get { + if ((curObj["CreationTime"] != null)) { + return ToDateTime(((string)(curObj["CreationTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The friendly name for the virtual system or snapshot.")] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The current state of the virtual system or snapshot.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The name of the guest operating system, if available. If this information is not " + + "available, the value of this property is NULL. This property is not valid for in" + + "stances of Msvm_SummaryInformation representing a virtual system snapshot.")] + public string GuestOperatingSystem { + get { + return ((string)(curObj["GuestOperatingSystem"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The current health state for the virtual system. This property is not valid for i" + + "nstances of Msvm_SummaryInformation representing a virtual system snapshot.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHeartbeatNull { + get { + if ((curObj["Heartbeat"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"The current heartbeat status for the virtual system. This property may be one of the following values: ""OK""; ""Error""; ""No Contact""; or ""Lost Communication"". For more information, see the documentation for the StatusDescriptions property of the Msvm_HeartbeatComponent class. This property is not valid for instances of Msvm_SummaryInformation representing a virtual system snapshot.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort Heartbeat { + get { + if ((curObj["Heartbeat"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["Heartbeat"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsIntegrationServicesVersionStateNull { + get { + if ((curObj["IntegrationServicesVersionState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Whether or not the integration services installed in the virtual machine are up t" + + "o date")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public IntegrationServicesVersionStateValues IntegrationServicesVersionState { + get { + if ((curObj["IntegrationServicesVersionState"] == null)) { + return ((IntegrationServicesVersionStateValues)(System.Convert.ToInt32(3))); + } + return ((IntegrationServicesVersionStateValues)(System.Convert.ToInt32(curObj["IntegrationServicesVersionState"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMemoryAvailableNull { + get { + if ((curObj["MemoryAvailable"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The memory available percentage in the virtual system.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public int MemoryAvailable { + get { + if ((curObj["MemoryAvailable"] == null)) { + return System.Convert.ToInt32(0); + } + return ((int)(curObj["MemoryAvailable"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMemorySpansPhysicalNumaNodesNull { + get { + if ((curObj["MemorySpansPhysicalNumaNodes"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates whether or not the memory of the one or more of the virtual non-uniform" + + " memory access (NUMA) nodes of the virtual machine spans multiple physical NUMA " + + "nodes of the hosting computer system.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool MemorySpansPhysicalNumaNodes { + get { + if ((curObj["MemorySpansPhysicalNumaNodes"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["MemorySpansPhysicalNumaNodes"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMemoryUsageNull { + get { + if ((curObj["MemoryUsage"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The current memory usage of the virtual system. This property is not valid for in" + + "stances of Msvm_SummaryInformation representing a virtual system snapshot.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MemoryUsage { + get { + if ((curObj["MemoryUsage"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MemoryUsage"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The unique name for the virtual system or snapshot.")] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The notes associated with the virtual system or snapshot.")] + public string Notes { + get { + return ((string)(curObj["Notes"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsNumberOfProcessorsNull { + get { + if ((curObj["NumberOfProcessors"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The total number of virtual processors allocated to the virtual system or snapsho" + + "t.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort NumberOfProcessors { + get { + if ((curObj["NumberOfProcessors"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["NumberOfProcessors"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The current status of the element.")] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("A string that describes the enabled or disabled state of the element when the Ena" + + "bledState property is set to 1 (\"Other\"). This property must be set to null when" + + " EnabledState is any value other than 1.")] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsProcessorLoadNull { + get { + if ((curObj["ProcessorLoad"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The current processor usage of the virtual system. This property is not valid for" + + " instances of Msvm_SummaryInformation representing a virtual system snapshot.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ProcessorLoad { + get { + if ((curObj["ProcessorLoad"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ProcessorLoad"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("An array of the previous 100 samples of the processor usage for the virtual syste" + + "m. This property is not valid for instances of Msvm_SummaryInformation represent" + + "ing a virtual system snapshot.")] + public ushort[] ProcessorLoadHistory { + get { + return ((ushort[])(curObj["ProcessorLoadHistory"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReplicationHealthNull { + get { + if ((curObj["ReplicationHealth"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Replication health for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ReplicationHealthValues ReplicationHealth { + get { + if ((curObj["ReplicationHealth"] == null)) { + return ((ReplicationHealthValues)(System.Convert.ToInt32(4))); + } + return ((ReplicationHealthValues)(System.Convert.ToInt32(curObj["ReplicationHealth"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReplicationModeNull { + get { + if ((curObj["ReplicationMode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Identifies replication type for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ReplicationModeValues ReplicationMode { + get { + if ((curObj["ReplicationMode"] == null)) { + return ((ReplicationModeValues)(System.Convert.ToInt32(4))); + } + return ((ReplicationModeValues)(System.Convert.ToInt32(curObj["ReplicationMode"]))); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReplicationStateNull { + get { + if ((curObj["ReplicationState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Replication state for the virtual machine.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ReplicationStateValues ReplicationState { + get { + if ((curObj["ReplicationState"] == null)) { + return ((ReplicationStateValues)(System.Convert.ToInt32(12))); + } + return ((ReplicationStateValues)(System.Convert.ToInt32(curObj["ReplicationState"]))); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("An array of Msvm_VirtualSystemSettingData instances representing the snapshots fo" + + "r the virtual system. This property is not valid for instances of Msvm_SummaryIn" + + "formation representing a virtual system snapshot.")] + public System.Management.ManagementBaseObject[] Snapshots { + get { + return ((System.Management.ManagementBaseObject[])(curObj["Snapshots"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Strings that describe the various OperationalStatus array values.")] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsSwapFilesInUseNull { + get { + if ((curObj["SwapFilesInUse"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indecates if smart paging is active.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool SwapFilesInUse { + get { + if ((curObj["SwapFilesInUse"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["SwapFilesInUse"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Reference to the CIM_ComputerSystem instance representing the test replica virtua" + + "l system for the virtual machine. This property is not valid for instances of Ms" + + "vm_SummaryInformation representing a virtual system snapshot.")] + public System.Management.ManagementPath TestReplicaSystem { + get { + if ((curObj["TestReplicaSystem"] != null)) { + return new System.Management.ManagementPath(curObj["TestReplicaSystem"].ToString()); + } + return null; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("An array containing a small, thumbnail-sized image of the desktop for the virtual" + + " system or snapshot in RGB565 format.")] + public byte[] ThumbnailImage { + get { + return ((byte[])(curObj["ThumbnailImage"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsUpTimeNull { + get { + if ((curObj["UpTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The amount of time since the virtual system was last booted. This property is not" + + " valid for instances of Msvm_SummaryInformation representing a virtual system sn" + + "apshot.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong UpTime { + get { + if ((curObj["UpTime"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["UpTime"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeApplicationHealth() { + if ((this.IsApplicationHealthNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAvailableMemoryBuffer() { + if ((this.IsAvailableMemoryBufferNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeCreationTime() { + if ((this.IsCreationTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHeartbeat() { + if ((this.IsHeartbeatNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeIntegrationServicesVersionState() { + if ((this.IsIntegrationServicesVersionStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMemoryAvailable() { + if ((this.IsMemoryAvailableNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMemorySpansPhysicalNumaNodes() { + if ((this.IsMemorySpansPhysicalNumaNodesNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMemoryUsage() { + if ((this.IsMemoryUsageNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeNumberOfProcessors() { + if ((this.IsNumberOfProcessorsNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeProcessorLoad() { + if ((this.IsProcessorLoadNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReplicationHealth() { + if ((this.IsReplicationHealthNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReplicationMode() { + if ((this.IsReplicationModeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReplicationState() { + if ((this.IsReplicationStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeSwapFilesInUse() { + if ((this.IsSwapFilesInUseNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeUpTime() { + if ((this.IsUpTimeNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath() { + string strPath = "ROOT\\virtualization\\v2:Msvm_SummaryInformation"; + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static SummaryInformationCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static SummaryInformationCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static SummaryInformationCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static SummaryInformationCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_SummaryInformation"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new SummaryInformationCollection(clsObject.GetInstances(enumOptions)); + } + + public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static SummaryInformationCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_SummaryInformation", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new SummaryInformationCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static SummaryInformation CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new SummaryInformation(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public enum ApplicationHealthValues { + + OK = 2, + + Application_Critical = 32782, + + Disabled = 32896, + + NULL_ENUM_VALUE = 0, + } + + public enum IntegrationServicesVersionStateValues { + + Unknown0 = 0, + + UpToDate = 1, + + Mismatch = 2, + + NULL_ENUM_VALUE = 3, + } + + public enum ReplicationHealthValues { + + Not_applicable = 0, + + Ok = 1, + + Warning = 2, + + Critical = 3, + + NULL_ENUM_VALUE = 4, + } + + public enum ReplicationModeValues { + + None = 0, + + Primary = 1, + + Recovery = 2, + + Test_Replica = 3, + + NULL_ENUM_VALUE = 4, + } + + public enum ReplicationStateValues { + + Disabled = 0, + + Ready_for_replication = 1, + + Waiting_to_complete_initial_replication = 2, + + Replicating = 3, + + Synced_replication_complete = 4, + + Recovered = 5, + + Committed = 6, + + Suspended = 7, + + Critical = 8, + + Waiting_to_start_resynchronization = 9, + + Resynchronizing = 10, + + Resynchronization_suspended = 11, + + NULL_ENUM_VALUE = 12, + } + + // Enumerator implementation for enumerating instances of the class. + public class SummaryInformationCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public SummaryInformationCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new SummaryInformation(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new SummaryInformationEnumerator(privColObj.GetEnumerator()); + } + + public class SummaryInformationEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public SummaryInformationEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new SummaryInformation(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SyntheticEthernetPortSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SyntheticEthernetPortSettingData.cs index 86be3a9d62a6..8759568d6c34 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SyntheticEthernetPortSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_SyntheticEthernetPortSettingData.cs @@ -15,1069 +15,1069 @@ // specific language governing permissions and limitations // under the License. -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_SyntheticEthernetPortSettingData - public class SyntheticEthernetPortSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_SyntheticEthernetPortSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public SyntheticEthernetPortSettingData() { - this.InitializeObject(null, null, null); - } - - public SyntheticEthernetPortSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(SyntheticEthernetPortSettingData.ConstructPath(keyInstanceID)), null); - } - - public SyntheticEthernetPortSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(SyntheticEthernetPortSettingData.ConstructPath(keyInstanceID)), null); - } - - public SyntheticEthernetPortSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public SyntheticEthernetPortSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public SyntheticEthernetPortSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public SyntheticEthernetPortSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public SyntheticEthernetPortSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public SyntheticEthernetPortSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Address { - get { - return ((string)(curObj["Address"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AddressOnParent { - get { - return ((string)(curObj["AddressOnParent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string AllocationUnits { - get { - return ((string)(curObj["AllocationUnits"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticAllocationNull { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticAllocation { - get { - if ((curObj["AutomaticAllocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticAllocation"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticDeallocationNull { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AutomaticDeallocation { - get { - if ((curObj["AutomaticDeallocation"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AutomaticDeallocation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Connection { - get { - return ((string[])(curObj["Connection"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsConsumerVisibilityNull { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ConsumerVisibility { - get { - if ((curObj["ConsumerVisibility"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ConsumerVisibility"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDesiredVLANEndpointModeNull { - get { - if ((curObj["DesiredVLANEndpointMode"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DesiredVLANEndpointMode { - get { - if ((curObj["DesiredVLANEndpointMode"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DesiredVLANEndpointMode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] HostResource { - get { - return ((string[])(curObj["HostResource"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLimitNull { - get { - if ((curObj["Limit"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Limit { - get { - if ((curObj["Limit"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Limit"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMappingBehaviorNull { - get { - if ((curObj["MappingBehavior"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort MappingBehavior { - get { - if ((curObj["MappingBehavior"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["MappingBehavior"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEndpointMode { - get { - return ((string)(curObj["OtherEndpointMode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherResourceType { - get { - return ((string)(curObj["OtherResourceType"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PoolID { - get { - return ((string)(curObj["PoolID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsReservationNull { - get { - if ((curObj["Reservation"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong Reservation { - get { - if ((curObj["Reservation"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["Reservation"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ResourceSubType { - get { - return ((string)(curObj["ResourceSubType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResourceTypeNull { - get { - if ((curObj["ResourceType"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResourceType { - get { - if ((curObj["ResourceType"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResourceType"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStaticMacAddressNull { - get { - if ((curObj["StaticMacAddress"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates a static MAC address.\nThis is a read-only property, but it can be chang" + - "ed using the ModifyVirtualSystemResources method of the Msvm_VirtualSystemManage" + - "mentService class.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool StaticMacAddress { - get { - if ((curObj["StaticMacAddress"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["StaticMacAddress"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualQuantityNull { - get { - if ((curObj["VirtualQuantity"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong VirtualQuantity { - get { - if ((curObj["VirtualQuantity"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["VirtualQuantity"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualQuantityUnits { - get { - return ((string)(curObj["VirtualQuantityUnits"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_SyntheticEthernetPortSettingData + public class SyntheticEthernetPortSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_SyntheticEthernetPortSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public SyntheticEthernetPortSettingData() { + this.InitializeObject(null, null, null); + } + + public SyntheticEthernetPortSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(SyntheticEthernetPortSettingData.ConstructPath(keyInstanceID)), null); + } + + public SyntheticEthernetPortSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(SyntheticEthernetPortSettingData.ConstructPath(keyInstanceID)), null); + } + + public SyntheticEthernetPortSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public SyntheticEthernetPortSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public SyntheticEthernetPortSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public SyntheticEthernetPortSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public SyntheticEthernetPortSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public SyntheticEthernetPortSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Address { + get { + return ((string)(curObj["Address"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AddressOnParent { + get { + return ((string)(curObj["AddressOnParent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string AllocationUnits { + get { + return ((string)(curObj["AllocationUnits"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticAllocationNull { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticAllocation { + get { + if ((curObj["AutomaticAllocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticAllocation"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticDeallocationNull { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AutomaticDeallocation { + get { + if ((curObj["AutomaticDeallocation"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AutomaticDeallocation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Connection { + get { + return ((string[])(curObj["Connection"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsConsumerVisibilityNull { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ConsumerVisibility { + get { + if ((curObj["ConsumerVisibility"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ConsumerVisibility"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDesiredVLANEndpointModeNull { + get { + if ((curObj["DesiredVLANEndpointMode"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DesiredVLANEndpointMode { + get { + if ((curObj["DesiredVLANEndpointMode"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DesiredVLANEndpointMode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] HostResource { + get { + return ((string[])(curObj["HostResource"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLimitNull { + get { + if ((curObj["Limit"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Limit { + get { + if ((curObj["Limit"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Limit"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMappingBehaviorNull { + get { + if ((curObj["MappingBehavior"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort MappingBehavior { + get { + if ((curObj["MappingBehavior"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["MappingBehavior"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEndpointMode { + get { + return ((string)(curObj["OtherEndpointMode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherResourceType { + get { + return ((string)(curObj["OtherResourceType"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PoolID { + get { + return ((string)(curObj["PoolID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsReservationNull { + get { + if ((curObj["Reservation"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong Reservation { + get { + if ((curObj["Reservation"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["Reservation"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ResourceSubType { + get { + return ((string)(curObj["ResourceSubType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResourceTypeNull { + get { + if ((curObj["ResourceType"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResourceType { + get { + if ((curObj["ResourceType"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResourceType"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStaticMacAddressNull { + get { + if ((curObj["StaticMacAddress"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates a static MAC address.\nThis is a read-only property, but it can be chang" + + "ed using the ModifyVirtualSystemResources method of the Msvm_VirtualSystemManage" + + "mentService class.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool StaticMacAddress { + get { + if ((curObj["StaticMacAddress"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["StaticMacAddress"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualQuantityNull { + get { + if ((curObj["VirtualQuantity"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong VirtualQuantity { + get { + if ((curObj["VirtualQuantity"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["VirtualQuantity"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualQuantityUnits { + get { + return ((string)(curObj["VirtualQuantityUnits"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"A free-form string array of identifiers of this resource presented to the virtual computer system's operating system. The indexes and values per index are defined on a per resource basis (that is, for each enumerated ResourceType value). This property is set to ""GUID"". -This is a read-only property, but it can be changed using the ModifyVirtualSystemResources method of the sd class.")] - public string[] VirtualSystemIdentifiers { - get { - return ((string[])(curObj["VirtualSystemIdentifiers"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsWeightNull { - get { - if ((curObj["Weight"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint Weight { - get { - if ((curObj["Weight"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["Weight"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeAutomaticAllocation() { - if ((this.IsAutomaticAllocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticDeallocation() { - if ((this.IsAutomaticDeallocationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeConsumerVisibility() { - if ((this.IsConsumerVisibilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDesiredVLANEndpointMode() { - if ((this.IsDesiredVLANEndpointModeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeLimit() { - if ((this.IsLimitNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMappingBehavior() { - if ((this.IsMappingBehaviorNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeReservation() { - if ((this.IsReservationNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResourceType() { - if ((this.IsResourceTypeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStaticMacAddress() { - if ((this.IsStaticMacAddressNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualQuantity() { - if ((this.IsVirtualQuantityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeWeight() { - if ((this.IsWeightNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_SyntheticEthernetPortSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static SyntheticEthernetPortSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static SyntheticEthernetPortSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static SyntheticEthernetPortSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static SyntheticEthernetPortSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_SyntheticEthernetPortSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new SyntheticEthernetPortSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_SyntheticEthernetPortSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new SyntheticEthernetPortSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static SyntheticEthernetPortSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new SyntheticEthernetPortSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class SyntheticEthernetPortSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public SyntheticEthernetPortSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new SyntheticEthernetPortSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new SyntheticEthernetPortSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class SyntheticEthernetPortSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public SyntheticEthernetPortSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new SyntheticEthernetPortSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +This is a read-only property, but it can be changed using the ModifyVirtualSystemResources method of the sd class.")] + public string[] VirtualSystemIdentifiers { + get { + return ((string[])(curObj["VirtualSystemIdentifiers"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsWeightNull { + get { + if ((curObj["Weight"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint Weight { + get { + if ((curObj["Weight"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["Weight"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeAutomaticAllocation() { + if ((this.IsAutomaticAllocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticDeallocation() { + if ((this.IsAutomaticDeallocationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeConsumerVisibility() { + if ((this.IsConsumerVisibilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDesiredVLANEndpointMode() { + if ((this.IsDesiredVLANEndpointModeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeLimit() { + if ((this.IsLimitNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMappingBehavior() { + if ((this.IsMappingBehaviorNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeReservation() { + if ((this.IsReservationNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResourceType() { + if ((this.IsResourceTypeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStaticMacAddress() { + if ((this.IsStaticMacAddressNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualQuantity() { + if ((this.IsVirtualQuantityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeWeight() { + if ((this.IsWeightNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_SyntheticEthernetPortSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static SyntheticEthernetPortSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static SyntheticEthernetPortSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static SyntheticEthernetPortSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static SyntheticEthernetPortSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_SyntheticEthernetPortSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new SyntheticEthernetPortSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static SyntheticEthernetPortSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_SyntheticEthernetPortSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new SyntheticEthernetPortSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static SyntheticEthernetPortSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new SyntheticEthernetPortSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class SyntheticEthernetPortSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public SyntheticEthernetPortSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new SyntheticEthernetPortSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new SyntheticEthernetPortSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class SyntheticEthernetPortSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public SyntheticEthernetPortSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new SyntheticEthernetPortSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitch.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitch.cs index 6ab4069bbe82..28ab749e828d 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitch.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitch.cs @@ -1,1386 +1,1386 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_VirtualEthernetSwitch - public class VirtualEthernetSwitch : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_VirtualEthernetSwitch"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public VirtualEthernetSwitch() { - this.InitializeObject(null, null, null); - } - - public VirtualEthernetSwitch(string keyCreationClassName, string keyName) { - this.InitializeObject(null, new System.Management.ManagementPath(VirtualEthernetSwitch.ConstructPath(keyCreationClassName, keyName)), null); - } - - public VirtualEthernetSwitch(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualEthernetSwitch.ConstructPath(keyCreationClassName, keyName)), null); - } - - public VirtualEthernetSwitch(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public VirtualEthernetSwitch(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public VirtualEthernetSwitch(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public VirtualEthernetSwitch(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public VirtualEthernetSwitch(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public VirtualEthernetSwitch(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] Dedicated { - get { - return ((ushort[])(curObj["Dedicated"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] IdentifyingDescriptions { - get { - return ((string[])(curObj["IdentifyingDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxIOVOffloadsNull { - get { - if ((curObj["MaxIOVOffloads"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum number of SR-IOV Virtual Function offloads available on this switch.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint MaxIOVOffloads { - get { - if ((curObj["MaxIOVOffloads"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["MaxIOVOffloads"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxVMQOffloadsNull { - get { - if ((curObj["MaxVMQOffloads"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum number of VMQ offloads allowed for a port on this switch.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint MaxVMQOffloads { - get { - if ((curObj["MaxVMQOffloads"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["MaxVMQOffloads"])); - } - set { - curObj["MaxVMQOffloads"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string NameFormat { - get { - return ((string)(curObj["NameFormat"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherDedicatedDescriptions { - get { - return ((string[])(curObj["OtherDedicatedDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] OtherIdentifyingInfo { - get { - return ((string[])(curObj["OtherIdentifyingInfo"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] PowerManagementCapabilities { - get { - return ((ushort[])(curObj["PowerManagementCapabilities"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerContact { - get { - return ((string)(curObj["PrimaryOwnerContact"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerName { - get { - return ((string)(curObj["PrimaryOwnerName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsResetCapabilityNull { - get { - if ((curObj["ResetCapability"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort ResetCapability { - get { - if ((curObj["ResetCapability"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["ResetCapability"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Roles { - get { - return ((string[])(curObj["Roles"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxIOVOffloads() { - if ((this.IsMaxIOVOffloadsNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeMaxVMQOffloads() { - if ((this.IsMaxVMQOffloadsNull == false)) { - return true; - } - return false; - } - - private void ResetMaxVMQOffloads() { - curObj["MaxVMQOffloads"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeResetCapability() { - if ((this.IsResetCapabilityNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualEthernetSwitch"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static VirtualEthernetSwitchCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static VirtualEthernetSwitchCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static VirtualEthernetSwitchCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static VirtualEthernetSwitchCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_VirtualEthernetSwitch"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new VirtualEthernetSwitchCollection(clsObject.GetInstances(enumOptions)); - } - - public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualEthernetSwitch", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new VirtualEthernetSwitchCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static VirtualEthernetSwitch CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new VirtualEthernetSwitch(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint SetPowerState(uint PowerState, System.DateTime Time) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); - inParams["PowerState"] = ((uint)(PowerState)); - inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class VirtualEthernetSwitchCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public VirtualEthernetSwitchCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new VirtualEthernetSwitch(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new VirtualEthernetSwitchEnumerator(privColObj.GetEnumerator()); - } - - public class VirtualEthernetSwitchEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public VirtualEthernetSwitchEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new VirtualEthernetSwitch(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_VirtualEthernetSwitch + public class VirtualEthernetSwitch : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_VirtualEthernetSwitch"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public VirtualEthernetSwitch() { + this.InitializeObject(null, null, null); + } + + public VirtualEthernetSwitch(string keyCreationClassName, string keyName) { + this.InitializeObject(null, new System.Management.ManagementPath(VirtualEthernetSwitch.ConstructPath(keyCreationClassName, keyName)), null); + } + + public VirtualEthernetSwitch(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualEthernetSwitch.ConstructPath(keyCreationClassName, keyName)), null); + } + + public VirtualEthernetSwitch(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public VirtualEthernetSwitch(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public VirtualEthernetSwitch(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public VirtualEthernetSwitch(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public VirtualEthernetSwitch(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public VirtualEthernetSwitch(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] Dedicated { + get { + return ((ushort[])(curObj["Dedicated"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] IdentifyingDescriptions { + get { + return ((string[])(curObj["IdentifyingDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxIOVOffloadsNull { + get { + if ((curObj["MaxIOVOffloads"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum number of SR-IOV Virtual Function offloads available on this switch.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint MaxIOVOffloads { + get { + if ((curObj["MaxIOVOffloads"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["MaxIOVOffloads"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxVMQOffloadsNull { + get { + if ((curObj["MaxVMQOffloads"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum number of VMQ offloads allowed for a port on this switch.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint MaxVMQOffloads { + get { + if ((curObj["MaxVMQOffloads"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["MaxVMQOffloads"])); + } + set { + curObj["MaxVMQOffloads"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string NameFormat { + get { + return ((string)(curObj["NameFormat"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherDedicatedDescriptions { + get { + return ((string[])(curObj["OtherDedicatedDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] OtherIdentifyingInfo { + get { + return ((string[])(curObj["OtherIdentifyingInfo"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] PowerManagementCapabilities { + get { + return ((ushort[])(curObj["PowerManagementCapabilities"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerContact { + get { + return ((string)(curObj["PrimaryOwnerContact"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerName { + get { + return ((string)(curObj["PrimaryOwnerName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsResetCapabilityNull { + get { + if ((curObj["ResetCapability"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort ResetCapability { + get { + if ((curObj["ResetCapability"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["ResetCapability"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Roles { + get { + return ((string[])(curObj["Roles"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxIOVOffloads() { + if ((this.IsMaxIOVOffloadsNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeMaxVMQOffloads() { + if ((this.IsMaxVMQOffloadsNull == false)) { + return true; + } + return false; + } + + private void ResetMaxVMQOffloads() { + curObj["MaxVMQOffloads"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeResetCapability() { + if ((this.IsResetCapabilityNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualEthernetSwitch"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static VirtualEthernetSwitchCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static VirtualEthernetSwitchCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static VirtualEthernetSwitchCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static VirtualEthernetSwitchCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_VirtualEthernetSwitch"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new VirtualEthernetSwitchCollection(clsObject.GetInstances(enumOptions)); + } + + public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static VirtualEthernetSwitchCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualEthernetSwitch", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new VirtualEthernetSwitchCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static VirtualEthernetSwitch CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new VirtualEthernetSwitch(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint SetPowerState(uint PowerState, System.DateTime Time) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetPowerState"); + inParams["PowerState"] = ((uint)(PowerState)); + inParams["Time"] = ToDmtfDateTime(((System.DateTime)(Time))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetPowerState", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class VirtualEthernetSwitchCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public VirtualEthernetSwitchCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new VirtualEthernetSwitch(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new VirtualEthernetSwitchEnumerator(privColObj.GetEnumerator()); + } + + public class VirtualEthernetSwitchEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public VirtualEthernetSwitchEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new VirtualEthernetSwitch(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitchManagementService.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitchManagementService.cs index ee167a7cd812..311668159458 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitchManagementService.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualEthernetSwitchManagementService.cs @@ -1,1515 +1,1515 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_VirtualEthernetSwitchManagementService - public class VirtualEthernetSwitchManagementService : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_VirtualEthernetSwitchManagementService"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public VirtualEthernetSwitchManagementService() { - this.InitializeObject(null, null, null); - } - - public VirtualEthernetSwitchManagementService(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(null, new System.Management.ManagementPath(VirtualEthernetSwitchManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public VirtualEthernetSwitchManagementService(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualEthernetSwitchManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public VirtualEthernetSwitchManagementService(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public VirtualEthernetSwitchManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public VirtualEthernetSwitchManagementService(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public VirtualEthernetSwitchManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public VirtualEthernetSwitchManagementService(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public VirtualEthernetSwitchManagementService(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerContact { - get { - return ((string)(curObj["PrimaryOwnerContact"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerName { - get { - return ((string)(curObj["PrimaryOwnerName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStartedNull { - get { - if ((curObj["Started"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool Started { - get { - if ((curObj["Started"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["Started"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string StartMode { - get { - return ((string)(curObj["StartMode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemCreationClassName { - get { - return ((string)(curObj["SystemCreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemName { - get { - return ((string)(curObj["SystemName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStarted() { - if ((this.IsStartedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualEthernetSwitchManagementService"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static VirtualEthernetSwitchManagementServiceCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static VirtualEthernetSwitchManagementServiceCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static VirtualEthernetSwitchManagementServiceCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static VirtualEthernetSwitchManagementServiceCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_VirtualEthernetSwitchManagementService"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new VirtualEthernetSwitchManagementServiceCollection(clsObject.GetInstances(enumOptions)); - } - - public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualEthernetSwitchManagementService", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new VirtualEthernetSwitchManagementServiceCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static VirtualEthernetSwitchManagementService CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new VirtualEthernetSwitchManagementService(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint AddFeatureSettings(System.Management.ManagementPath AffectedConfiguration, string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("AddFeatureSettings"); - inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; - inParams["FeatureSettings"] = ((string[])(FeatureSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddFeatureSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - ResultingFeatureSettings = null; - if ((outParams.Properties["ResultingFeatureSettings"] != null)) { - int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingFeatureSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingFeatureSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint AddResourceSettings(System.Management.ManagementPath AffectedConfiguration, string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("AddResourceSettings"); - inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; - inParams["ResourceSettings"] = ((string[])(ResourceSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddResourceSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - ResultingResourceSettings = null; - if ((outParams.Properties["ResultingResourceSettings"] != null)) { - int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingResourceSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingResourceSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint DefineSystem(System.Management.ManagementPath ReferenceConfiguration, string[] ResourceSettings, string SystemSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath ResultingSystem) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("DefineSystem"); - inParams["ReferenceConfiguration"] = ((System.Management.ManagementPath)(ReferenceConfiguration)).Path; - inParams["ResourceSettings"] = ((string[])(ResourceSettings)); - inParams["SystemSettings"] = ((string)(SystemSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DefineSystem", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - ResultingSystem = null; - if ((outParams.Properties["ResultingSystem"] != null)) { - ResultingSystem = new System.Management.ManagementPath(outParams.Properties["ResultingSystem"].ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingSystem = null; - return System.Convert.ToUInt32(0); - } - } - - public uint DestroySystem(System.Management.ManagementPath AffectedSystem, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("DestroySystem"); - inParams["AffectedSystem"] = ((System.Management.ManagementPath)(AffectedSystem)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DestroySystem", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifyFeatureSettings(string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifyFeatureSettings"); - inParams["FeatureSettings"] = ((string[])(FeatureSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyFeatureSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - ResultingFeatureSettings = null; - if ((outParams.Properties["ResultingFeatureSettings"] != null)) { - int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingFeatureSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingFeatureSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifyResourceSettings(string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifyResourceSettings"); - inParams["ResourceSettings"] = ((string[])(ResourceSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyResourceSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - ResultingResourceSettings = null; - if ((outParams.Properties["ResultingResourceSettings"] != null)) { - int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingResourceSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingResourceSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifySystemSettings(string SystemSettings, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifySystemSettings"); - inParams["SystemSettings"] = ((string)(SystemSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifySystemSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RemoveFeatureSettings(System.Management.ManagementPath[] FeatureSettings, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RemoveFeatureSettings"); - if ((FeatureSettings != null)) { - int len = ((System.Array)(FeatureSettings)).Length; - string[] arrProp = new string[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(FeatureSettings)).GetValue(iCounter))).Path; - } - inParams["FeatureSettings"] = arrProp; - } - else { - inParams["FeatureSettings"] = null; - } - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveFeatureSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RemoveResourceSettings(System.Management.ManagementPath[] ResourceSettings, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RemoveResourceSettings"); - if ((ResourceSettings != null)) { - int len = ((System.Array)(ResourceSettings)).Length; - string[] arrProp = new string[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(ResourceSettings)).GetValue(iCounter))).Path; - } - inParams["ResourceSettings"] = arrProp; - } - else { - inParams["ResourceSettings"] = null; - } - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveResourceSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) - { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { - Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint StartService() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StartService", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint StopService() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StopService", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class VirtualEthernetSwitchManagementServiceCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public VirtualEthernetSwitchManagementServiceCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new VirtualEthernetSwitchManagementService(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new VirtualEthernetSwitchManagementServiceEnumerator(privColObj.GetEnumerator()); - } - - public class VirtualEthernetSwitchManagementServiceEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public VirtualEthernetSwitchManagementServiceEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new VirtualEthernetSwitchManagementService(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_VirtualEthernetSwitchManagementService + public class VirtualEthernetSwitchManagementService : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_VirtualEthernetSwitchManagementService"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public VirtualEthernetSwitchManagementService() { + this.InitializeObject(null, null, null); + } + + public VirtualEthernetSwitchManagementService(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(null, new System.Management.ManagementPath(VirtualEthernetSwitchManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public VirtualEthernetSwitchManagementService(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualEthernetSwitchManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public VirtualEthernetSwitchManagementService(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public VirtualEthernetSwitchManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public VirtualEthernetSwitchManagementService(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public VirtualEthernetSwitchManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public VirtualEthernetSwitchManagementService(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public VirtualEthernetSwitchManagementService(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerContact { + get { + return ((string)(curObj["PrimaryOwnerContact"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerName { + get { + return ((string)(curObj["PrimaryOwnerName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStartedNull { + get { + if ((curObj["Started"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool Started { + get { + if ((curObj["Started"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["Started"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string StartMode { + get { + return ((string)(curObj["StartMode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemCreationClassName { + get { + return ((string)(curObj["SystemCreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemName { + get { + return ((string)(curObj["SystemName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStarted() { + if ((this.IsStartedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualEthernetSwitchManagementService"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static VirtualEthernetSwitchManagementServiceCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static VirtualEthernetSwitchManagementServiceCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static VirtualEthernetSwitchManagementServiceCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static VirtualEthernetSwitchManagementServiceCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_VirtualEthernetSwitchManagementService"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new VirtualEthernetSwitchManagementServiceCollection(clsObject.GetInstances(enumOptions)); + } + + public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static VirtualEthernetSwitchManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualEthernetSwitchManagementService", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new VirtualEthernetSwitchManagementServiceCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static VirtualEthernetSwitchManagementService CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new VirtualEthernetSwitchManagementService(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint AddFeatureSettings(System.Management.ManagementPath AffectedConfiguration, string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("AddFeatureSettings"); + inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; + inParams["FeatureSettings"] = ((string[])(FeatureSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddFeatureSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + ResultingFeatureSettings = null; + if ((outParams.Properties["ResultingFeatureSettings"] != null)) { + int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingFeatureSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingFeatureSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint AddResourceSettings(System.Management.ManagementPath AffectedConfiguration, string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("AddResourceSettings"); + inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; + inParams["ResourceSettings"] = ((string[])(ResourceSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddResourceSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + ResultingResourceSettings = null; + if ((outParams.Properties["ResultingResourceSettings"] != null)) { + int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingResourceSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingResourceSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint DefineSystem(System.Management.ManagementPath ReferenceConfiguration, string[] ResourceSettings, string SystemSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath ResultingSystem) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("DefineSystem"); + inParams["ReferenceConfiguration"] = ((System.Management.ManagementPath)(ReferenceConfiguration)).Path; + inParams["ResourceSettings"] = ((string[])(ResourceSettings)); + inParams["SystemSettings"] = ((string)(SystemSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DefineSystem", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + ResultingSystem = null; + if ((outParams.Properties["ResultingSystem"] != null)) { + ResultingSystem = new System.Management.ManagementPath(outParams.Properties["ResultingSystem"].ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingSystem = null; + return System.Convert.ToUInt32(0); + } + } + + public uint DestroySystem(System.Management.ManagementPath AffectedSystem, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("DestroySystem"); + inParams["AffectedSystem"] = ((System.Management.ManagementPath)(AffectedSystem)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DestroySystem", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifyFeatureSettings(string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifyFeatureSettings"); + inParams["FeatureSettings"] = ((string[])(FeatureSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyFeatureSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + ResultingFeatureSettings = null; + if ((outParams.Properties["ResultingFeatureSettings"] != null)) { + int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingFeatureSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingFeatureSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifyResourceSettings(string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifyResourceSettings"); + inParams["ResourceSettings"] = ((string[])(ResourceSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyResourceSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + ResultingResourceSettings = null; + if ((outParams.Properties["ResultingResourceSettings"] != null)) { + int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingResourceSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingResourceSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifySystemSettings(string SystemSettings, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifySystemSettings"); + inParams["SystemSettings"] = ((string)(SystemSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifySystemSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RemoveFeatureSettings(System.Management.ManagementPath[] FeatureSettings, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RemoveFeatureSettings"); + if ((FeatureSettings != null)) { + int len = ((System.Array)(FeatureSettings)).Length; + string[] arrProp = new string[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(FeatureSettings)).GetValue(iCounter))).Path; + } + inParams["FeatureSettings"] = arrProp; + } + else { + inParams["FeatureSettings"] = null; + } + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveFeatureSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RemoveResourceSettings(System.Management.ManagementPath[] ResourceSettings, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RemoveResourceSettings"); + if ((ResourceSettings != null)) { + int len = ((System.Array)(ResourceSettings)).Length; + string[] arrProp = new string[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(ResourceSettings)).GetValue(iCounter))).Path; + } + inParams["ResourceSettings"] = arrProp; + } + else { + inParams["ResourceSettings"] = null; + } + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveResourceSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) + { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) { + Job = new System.Management.ManagementPath(outParams.Properties["Job"].Value.ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint StartService() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StartService", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint StopService() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StopService", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class VirtualEthernetSwitchManagementServiceCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public VirtualEthernetSwitchManagementServiceCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new VirtualEthernetSwitchManagementService(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new VirtualEthernetSwitchManagementServiceEnumerator(privColObj.GetEnumerator()); + } + + public class VirtualEthernetSwitchManagementServiceEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public VirtualEthernetSwitchManagementServiceEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new VirtualEthernetSwitchManagementService(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualHardDiskSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualHardDiskSettingData.cs index 94851c54cc70..9f1a738e4ebb 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualHardDiskSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualHardDiskSettingData.cs @@ -1,1051 +1,1051 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_VirtualHardDiskSettingData - public class VirtualHardDiskSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_VirtualHardDiskSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public VirtualHardDiskSettingData() { - this.InitializeObject(null, null, null); - } - - public VirtualHardDiskSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(VirtualHardDiskSettingData.ConstructPath(keyInstanceID)), null); - } - - public VirtualHardDiskSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualHardDiskSettingData.ConstructPath(keyInstanceID)), null); - } - - public VirtualHardDiskSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public VirtualHardDiskSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public VirtualHardDiskSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public VirtualHardDiskSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public VirtualHardDiskSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public VirtualHardDiskSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsBlockSizeNull { - get { - if ((curObj["BlockSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The block size used by the virtual hard disk")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint BlockSize { - get { - if ((curObj["BlockSize"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["BlockSize"])); - } - set { - curObj["BlockSize"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - set { - curObj["Caption"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - set { - curObj["Description"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - set { - curObj["ElementName"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsFormatNull { - get { - if ((curObj["Format"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The format for the virtual hard disk.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public FormatValues Format { - get { - if ((curObj["Format"] == null)) { - return ((FormatValues)(System.Convert.ToInt32(0))); - } - return ((FormatValues)(System.Convert.ToInt32(curObj["Format"]))); - } - set { - if ((FormatValues.NULL_ENUM_VALUE == value)) { - curObj["Format"] = null; - } - else { - curObj["Format"] = value; - } - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - set { - curObj["InstanceID"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsLogicalSectorSizeNull { - get { - if ((curObj["LogicalSectorSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The logical sector size used by the virtual hard disk")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint LogicalSectorSize { - get { - if ((curObj["LogicalSectorSize"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["LogicalSectorSize"])); - } - set { - curObj["LogicalSectorSize"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsMaxInternalSizeNull { - get { - if ((curObj["MaxInternalSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum size of the virtual hard disk as viewable by the virtual machine, in " + - "bytes. The specified size will be rounded up to the next largest multiple of the" + - " sector size.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ulong MaxInternalSize { - get { - if ((curObj["MaxInternalSize"] == null)) { - return System.Convert.ToUInt64(0); - } - return ((ulong)(curObj["MaxInternalSize"])); - } - set { - curObj["MaxInternalSize"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The parent of the virtual hard disk. If the virtual hard disk does not have a par" + - "ent, then this field is empty.")] - public string ParentPath { - get { - return ((string)(curObj["ParentPath"])); - } - set { - curObj["ParentPath"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The path of the virtual hard disk.")] - public string Path0 { - get { - return ((string)(curObj["Path"])); - } - set { - curObj["Path"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPhysicalSectorSizeNull { - get { - if ((curObj["PhysicalSectorSize"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The physical sector size used by the virtual hard disk")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint PhysicalSectorSize { - get { - if ((curObj["PhysicalSectorSize"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["PhysicalSectorSize"])); - } - set { - curObj["PhysicalSectorSize"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTypeNull { - get { - if ((curObj["Type"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The type of virtual hard disk.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public TypeValues Type { - get { - if ((curObj["Type"] == null)) { - return ((TypeValues)(System.Convert.ToInt32(0))); - } - return ((TypeValues)(System.Convert.ToInt32(curObj["Type"]))); - } - set { - if ((TypeValues.NULL_ENUM_VALUE == value)) { - curObj["Type"] = null; - } - else { - curObj["Type"] = value; - } - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeBlockSize() { - if ((this.IsBlockSizeNull == false)) { - return true; - } - return false; - } - - private void ResetBlockSize() { - curObj["BlockSize"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetCaption() { - curObj["Caption"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetDescription() { - curObj["Description"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetElementName() { - curObj["ElementName"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeFormat() { - if ((this.IsFormatNull == false)) { - return true; - } - return false; - } - - private void ResetFormat() { - curObj["Format"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeLogicalSectorSize() { - if ((this.IsLogicalSectorSizeNull == false)) { - return true; - } - return false; - } - - private void ResetLogicalSectorSize() { - curObj["LogicalSectorSize"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeMaxInternalSize() { - if ((this.IsMaxInternalSizeNull == false)) { - return true; - } - return false; - } - - private void ResetMaxInternalSize() { - curObj["MaxInternalSize"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetParentPath() { - curObj["ParentPath"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetPath0() { - curObj["Path"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializePhysicalSectorSize() { - if ((this.IsPhysicalSectorSizeNull == false)) { - return true; - } - return false; - } - - private void ResetPhysicalSectorSize() { - curObj["PhysicalSectorSize"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeType() { - if ((this.IsTypeNull == false)) { - return true; - } - return false; - } - - private void ResetType() { - curObj["Type"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualHardDiskSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static VirtualHardDiskSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static VirtualHardDiskSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static VirtualHardDiskSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static VirtualHardDiskSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_VirtualHardDiskSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new VirtualHardDiskSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualHardDiskSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new VirtualHardDiskSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static VirtualHardDiskSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new VirtualHardDiskSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public enum FormatValues { - - VHD = 2, - - VHDX = 3, - - NULL_ENUM_VALUE = 0, - } - - public enum TypeValues { - - Fixed = 2, - - Dynamic = 3, - - Differencing = 4, - - NULL_ENUM_VALUE = 0, - } - - // Enumerator implementation for enumerating instances of the class. - public class VirtualHardDiskSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public VirtualHardDiskSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new VirtualHardDiskSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new VirtualHardDiskSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class VirtualHardDiskSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public VirtualHardDiskSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new VirtualHardDiskSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_VirtualHardDiskSettingData + public class VirtualHardDiskSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_VirtualHardDiskSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public VirtualHardDiskSettingData() { + this.InitializeObject(null, null, null); + } + + public VirtualHardDiskSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(VirtualHardDiskSettingData.ConstructPath(keyInstanceID)), null); + } + + public VirtualHardDiskSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualHardDiskSettingData.ConstructPath(keyInstanceID)), null); + } + + public VirtualHardDiskSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public VirtualHardDiskSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public VirtualHardDiskSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public VirtualHardDiskSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public VirtualHardDiskSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public VirtualHardDiskSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsBlockSizeNull { + get { + if ((curObj["BlockSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The block size used by the virtual hard disk")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint BlockSize { + get { + if ((curObj["BlockSize"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["BlockSize"])); + } + set { + curObj["BlockSize"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + set { + curObj["Caption"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + set { + curObj["Description"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + set { + curObj["ElementName"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsFormatNull { + get { + if ((curObj["Format"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The format for the virtual hard disk.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public FormatValues Format { + get { + if ((curObj["Format"] == null)) { + return ((FormatValues)(System.Convert.ToInt32(0))); + } + return ((FormatValues)(System.Convert.ToInt32(curObj["Format"]))); + } + set { + if ((FormatValues.NULL_ENUM_VALUE == value)) { + curObj["Format"] = null; + } + else { + curObj["Format"] = value; + } + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + set { + curObj["InstanceID"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsLogicalSectorSizeNull { + get { + if ((curObj["LogicalSectorSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The logical sector size used by the virtual hard disk")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint LogicalSectorSize { + get { + if ((curObj["LogicalSectorSize"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["LogicalSectorSize"])); + } + set { + curObj["LogicalSectorSize"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsMaxInternalSizeNull { + get { + if ((curObj["MaxInternalSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum size of the virtual hard disk as viewable by the virtual machine, in " + + "bytes. The specified size will be rounded up to the next largest multiple of the" + + " sector size.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ulong MaxInternalSize { + get { + if ((curObj["MaxInternalSize"] == null)) { + return System.Convert.ToUInt64(0); + } + return ((ulong)(curObj["MaxInternalSize"])); + } + set { + curObj["MaxInternalSize"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The parent of the virtual hard disk. If the virtual hard disk does not have a par" + + "ent, then this field is empty.")] + public string ParentPath { + get { + return ((string)(curObj["ParentPath"])); + } + set { + curObj["ParentPath"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The path of the virtual hard disk.")] + public string Path0 { + get { + return ((string)(curObj["Path"])); + } + set { + curObj["Path"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPhysicalSectorSizeNull { + get { + if ((curObj["PhysicalSectorSize"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The physical sector size used by the virtual hard disk")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint PhysicalSectorSize { + get { + if ((curObj["PhysicalSectorSize"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["PhysicalSectorSize"])); + } + set { + curObj["PhysicalSectorSize"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTypeNull { + get { + if ((curObj["Type"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The type of virtual hard disk.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public TypeValues Type { + get { + if ((curObj["Type"] == null)) { + return ((TypeValues)(System.Convert.ToInt32(0))); + } + return ((TypeValues)(System.Convert.ToInt32(curObj["Type"]))); + } + set { + if ((TypeValues.NULL_ENUM_VALUE == value)) { + curObj["Type"] = null; + } + else { + curObj["Type"] = value; + } + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeBlockSize() { + if ((this.IsBlockSizeNull == false)) { + return true; + } + return false; + } + + private void ResetBlockSize() { + curObj["BlockSize"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetCaption() { + curObj["Caption"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetDescription() { + curObj["Description"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetElementName() { + curObj["ElementName"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeFormat() { + if ((this.IsFormatNull == false)) { + return true; + } + return false; + } + + private void ResetFormat() { + curObj["Format"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeLogicalSectorSize() { + if ((this.IsLogicalSectorSizeNull == false)) { + return true; + } + return false; + } + + private void ResetLogicalSectorSize() { + curObj["LogicalSectorSize"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeMaxInternalSize() { + if ((this.IsMaxInternalSizeNull == false)) { + return true; + } + return false; + } + + private void ResetMaxInternalSize() { + curObj["MaxInternalSize"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetParentPath() { + curObj["ParentPath"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetPath0() { + curObj["Path"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializePhysicalSectorSize() { + if ((this.IsPhysicalSectorSizeNull == false)) { + return true; + } + return false; + } + + private void ResetPhysicalSectorSize() { + curObj["PhysicalSectorSize"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeType() { + if ((this.IsTypeNull == false)) { + return true; + } + return false; + } + + private void ResetType() { + curObj["Type"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualHardDiskSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static VirtualHardDiskSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static VirtualHardDiskSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static VirtualHardDiskSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static VirtualHardDiskSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_VirtualHardDiskSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new VirtualHardDiskSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static VirtualHardDiskSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualHardDiskSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new VirtualHardDiskSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static VirtualHardDiskSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new VirtualHardDiskSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public enum FormatValues { + + VHD = 2, + + VHDX = 3, + + NULL_ENUM_VALUE = 0, + } + + public enum TypeValues { + + Fixed = 2, + + Dynamic = 3, + + Differencing = 4, + + NULL_ENUM_VALUE = 0, + } + + // Enumerator implementation for enumerating instances of the class. + public class VirtualHardDiskSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public VirtualHardDiskSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new VirtualHardDiskSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new VirtualHardDiskSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class VirtualHardDiskSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public VirtualHardDiskSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new VirtualHardDiskSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementService.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementService.cs index 124cda26ca19..0aca9977e44d 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementService.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementService.cs @@ -1,1916 +1,1916 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 -{ - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_VirtualSystemManagementService - public class VirtualSystemManagementService : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - private static string CreatedClassName = "Msvm_VirtualSystemManagementService"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public VirtualSystemManagementService() { - this.InitializeObject(null, null, null); - } - - public VirtualSystemManagementService(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(null, new System.Management.ManagementPath(VirtualSystemManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public VirtualSystemManagementService(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualSystemManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); - } - - public VirtualSystemManagementService(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public VirtualSystemManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public VirtualSystemManagementService(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public VirtualSystemManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public VirtualSystemManagementService(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public VirtualSystemManagementService(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] AvailableRequestedStates { - get { - return ((ushort[])(curObj["AvailableRequestedStates"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCommunicationStatusNull { - get { - if ((curObj["CommunicationStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort CommunicationStatus { - get { - if ((curObj["CommunicationStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["CommunicationStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string CreationClassName { - get { - return ((string)(curObj["CreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDetailedStatusNull { - get { - if ((curObj["DetailedStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort DetailedStatus { - get { - if ((curObj["DetailedStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["DetailedStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledDefaultNull { - get { - if ((curObj["EnabledDefault"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledDefault { - get { - if ((curObj["EnabledDefault"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledDefault"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsEnabledStateNull { - get { - if ((curObj["EnabledState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort EnabledState { - get { - if ((curObj["EnabledState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["EnabledState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHealthStateNull { - get { - if ((curObj["HealthState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort HealthState { - get { - if ((curObj["HealthState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["HealthState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsInstallDateNull { - get { - if ((curObj["InstallDate"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime InstallDate { - get { - if ((curObj["InstallDate"] != null)) { - return ToDateTime(((string)(curObj["InstallDate"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Name { - get { - return ((string)(curObj["Name"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsOperatingStatusNull { - get { - if ((curObj["OperatingStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort OperatingStatus { - get { - if ((curObj["OperatingStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["OperatingStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ushort[] OperationalStatus { - get { - return ((ushort[])(curObj["OperationalStatus"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OtherEnabledState { - get { - return ((string)(curObj["OtherEnabledState"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerContact { - get { - return ((string)(curObj["PrimaryOwnerContact"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string PrimaryOwnerName { - get { - return ((string)(curObj["PrimaryOwnerName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsPrimaryStatusNull { - get { - if ((curObj["PrimaryStatus"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort PrimaryStatus { - get { - if ((curObj["PrimaryStatus"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["PrimaryStatus"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsRequestedStateNull { - get { - if ((curObj["RequestedState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort RequestedState { - get { - if ((curObj["RequestedState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["RequestedState"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsStartedNull { - get { - if ((curObj["Started"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool Started { - get { - if ((curObj["Started"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["Started"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string StartMode { - get { - return ((string)(curObj["StartMode"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Status { - get { - return ((string)(curObj["Status"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] StatusDescriptions { - get { - return ((string[])(curObj["StatusDescriptions"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemCreationClassName { - get { - return ((string)(curObj["SystemCreationClassName"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SystemName { - get { - return ((string)(curObj["SystemName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTimeOfLastStateChangeNull { - get { - if ((curObj["TimeOfLastStateChange"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime TimeOfLastStateChange { - get { - if ((curObj["TimeOfLastStateChange"] != null)) { - return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsTransitioningToStateNull { - get { - if ((curObj["TransitioningToState"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort TransitioningToState { - get { - if ((curObj["TransitioningToState"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["TransitioningToState"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeCommunicationStatus() { - if ((this.IsCommunicationStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDetailedStatus() { - if ((this.IsDetailedStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledDefault() { - if ((this.IsEnabledDefaultNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeEnabledState() { - if ((this.IsEnabledStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeHealthState() { - if ((this.IsHealthStateNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeInstallDate() { - if ((this.IsInstallDateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeOperatingStatus() { - if ((this.IsOperatingStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializePrimaryStatus() { - if ((this.IsPrimaryStatusNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeRequestedState() { - if ((this.IsRequestedStateNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeStarted() { - if ((this.IsStartedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTimeOfLastStateChange() { - if ((this.IsTimeOfLastStateChangeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeTransitioningToState() { - if ((this.IsTransitioningToStateNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { - string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualSystemManagementService"; - strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); - strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static VirtualSystemManagementServiceCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static VirtualSystemManagementServiceCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static VirtualSystemManagementServiceCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static VirtualSystemManagementServiceCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_VirtualSystemManagementService"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new VirtualSystemManagementServiceCollection(clsObject.GetInstances(enumOptions)); - } - - public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualSystemManagementService", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new VirtualSystemManagementServiceCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static VirtualSystemManagementService CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new VirtualSystemManagementService(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public uint AddFeatureSettings(System.Management.ManagementPath AffectedConfiguration, string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("AddFeatureSettings"); - inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; - inParams["FeatureSettings"] = ((string[])(FeatureSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddFeatureSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - ResultingFeatureSettings = null; - if ((outParams.Properties["ResultingFeatureSettings"] != null && outParams.Properties["ResultingFeatureSettings"].Value != null)) - { - int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingFeatureSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingFeatureSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint AddFibreChannelChap(string[] FcPortSettings, byte SecretEncoding, byte[] SharedSecret) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("AddFibreChannelChap"); - inParams["FcPortSettings"] = ((string[])(FcPortSettings)); - inParams["SecretEncoding"] = ((byte)(SecretEncoding)); - inParams["SharedSecret"] = ((byte[])(SharedSecret)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddFibreChannelChap", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint AddKvpItems(string[] DataItems, System.Management.ManagementPath TargetSystem, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("AddKvpItems"); - inParams["DataItems"] = ((string[])(DataItems)); - inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddKvpItems", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint AddResourceSettings(System.Management.ManagementPath AffectedConfiguration, string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("AddResourceSettings"); - inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; - inParams["ResourceSettings"] = ((string[])(ResourceSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddResourceSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - ResultingResourceSettings = null; - if ((outParams.Properties["ResultingResourceSettings"] != null && outParams.Properties["ResultingResourceSettings"].Value != null)) - { - int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingResourceSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingResourceSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint DefineSystem(string ReferenceConfigurationPath, string[] ResourceSettings, string SystemSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath ResultingSystem) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("DefineSystem"); - inParams["ReferenceConfiguration"] = ReferenceConfigurationPath; - inParams["ResourceSettings"] = ResourceSettings; - inParams["SystemSettings"] = SystemSettings; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DefineSystem", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - ResultingSystem = null; - if ((outParams.Properties["ResultingSystem"] != null && outParams.Properties["ResultingSystem"].Value != null)) - { - ResultingSystem = new System.Management.ManagementPath((string)outParams.Properties["ResultingSystem"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingSystem = null; - return System.Convert.ToUInt32(0); - } - } - - public uint DestroySystem(System.Management.ManagementPath AffectedSystem, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("DestroySystem"); - inParams["AffectedSystem"] = ((System.Management.ManagementPath)(AffectedSystem)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DestroySystem", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ExportSystemDefinition(System.Management.ManagementPath ComputerSystem, string ExportDirectory, string ExportSettingData, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ExportSystemDefinition"); - inParams["ComputerSystem"] = ((System.Management.ManagementPath)(ComputerSystem)).Path; - inParams["ExportDirectory"] = ((string)(ExportDirectory)); - inParams["ExportSettingData"] = ((string)(ExportSettingData)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ExportSystemDefinition", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint FormatError(string[] Errors, out string ErrorMessage) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("FormatError"); - inParams["Errors"] = ((string[])(Errors)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("FormatError", inParams, null); - ErrorMessage = System.Convert.ToString(outParams.Properties["ErrorMessage"].Value); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - ErrorMessage = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GenerateWwpn(uint NumberOfWwpns, out string[] GeneratedWwpn) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("GenerateWwpn"); - inParams["NumberOfWwpns"] = ((uint)(NumberOfWwpns)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GenerateWwpn", inParams, null); - GeneratedWwpn = ((string[])(outParams.Properties["GeneratedWwpn"].Value)); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - GeneratedWwpn = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GetCurrentWwpnFromGenerator(out string CurrentWwpn) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetCurrentWwpnFromGenerator", inParams, null); - CurrentWwpn = System.Convert.ToString(outParams.Properties["CurrentWwpn"].Value); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - CurrentWwpn = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GetDefinitionFileSummaryInformation(string[] DefinitionFiles, out System.Management.ManagementBaseObject[] SummaryInformation) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("GetDefinitionFileSummaryInformation"); - inParams["DefinitionFiles"] = ((string[])(DefinitionFiles)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetDefinitionFileSummaryInformation", inParams, null); - SummaryInformation = ((System.Management.ManagementBaseObject[])(outParams.Properties["SummaryInformation"].Value)); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - SummaryInformation = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GetSizeOfSystemFiles(System.Management.ManagementPath Vssd, out ulong Size) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("GetSizeOfSystemFiles"); - inParams["Vssd"] = ((System.Management.ManagementPath)(Vssd)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetSizeOfSystemFiles", inParams, null); - Size = System.Convert.ToUInt64(outParams.Properties["Size"].Value); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Size = System.Convert.ToUInt64(0); - return System.Convert.ToUInt32(0); - } - } - - public uint GetSummaryInformation(uint[] RequestedInformation, System.Management.ManagementPath[] SettingData, out System.Management.ManagementBaseObject[] SummaryInformation) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("GetSummaryInformation"); - inParams["RequestedInformation"] = ((uint[])(RequestedInformation)); - if ((SettingData != null)) { - int len = ((System.Array)(SettingData)).Length; - string[] arrProp = new string[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(SettingData)).GetValue(iCounter))).Path; - } - inParams["SettingData"] = arrProp; - } - else { - inParams["SettingData"] = null; - } - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetSummaryInformation", inParams, null); - SummaryInformation = ((System.Management.ManagementBaseObject[])(outParams.Properties["SummaryInformation"].Value)); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - SummaryInformation = null; - return System.Convert.ToUInt32(0); - } - } - - public uint GetVirtualSystemThumbnailImage(ushort HeightPixels, System.Management.ManagementPath TargetSystem, ushort WidthPixels, out byte[] ImageData) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("GetVirtualSystemThumbnailImage"); - inParams["HeightPixels"] = ((ushort)(HeightPixels)); - inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; - inParams["WidthPixels"] = ((ushort)(WidthPixels)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetVirtualSystemThumbnailImage", inParams, null); - ImageData = ((byte[])(outParams.Properties["ImageData"].Value)); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - ImageData = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ImportSnapshotDefinitions(System.Management.ManagementPath PlannedSystem, string SnapshotFolder, out System.Management.ManagementPath[] ImportedSnapshots, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ImportSnapshotDefinitions"); - inParams["PlannedSystem"] = ((System.Management.ManagementPath)(PlannedSystem)).Path; - inParams["SnapshotFolder"] = ((string)(SnapshotFolder)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ImportSnapshotDefinitions", inParams, null); - ImportedSnapshots = null; - if ((outParams.Properties["ImportedSnapshots"] != null && outParams.Properties["ImportedSnapshots"].Value != null)) - { - int len = ((System.Array)(outParams.Properties["ImportedSnapshots"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ImportedSnapshots"].Value)).GetValue(iCounter).ToString()); - } - ImportedSnapshots = arrToRet; - } - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - ImportedSnapshots = null; - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ImportSystemDefinition(bool GenerateNewSystemIdentifier, string SnapshotFolder, string SystemDefinitionFile, out System.Management.ManagementPath ImportedSystem, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ImportSystemDefinition"); - inParams["GenerateNewSystemIdentifier"] = ((bool)(GenerateNewSystemIdentifier)); - inParams["SnapshotFolder"] = ((string)(SnapshotFolder)); - inParams["SystemDefinitionFile"] = ((string)(SystemDefinitionFile)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ImportSystemDefinition", inParams, null); - ImportedSystem = null; - if ((outParams.Properties["ImportedSystem"] != null && outParams.Properties["ImportedSystem"].Value != null)) - { - ImportedSystem = new System.Management.ManagementPath(outParams.Properties["ImportedSystem"].ToString()); - } - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - ImportedSystem = null; - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifyDiskMergeSettings(string SettingData, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifyDiskMergeSettings"); - inParams["SettingData"] = ((string)(SettingData)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyDiskMergeSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifyFeatureSettings(string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifyFeatureSettings"); - inParams["FeatureSettings"] = ((string[])(FeatureSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyFeatureSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - ResultingFeatureSettings = null; - if ((outParams.Properties["ResultingFeatureSettings"] != null && outParams.Properties["ResultingFeatureSettings"].Value != null)) - { - int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingFeatureSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingFeatureSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifyKvpItems(string[] DataItems, System.Management.ManagementPath TargetSystem, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifyKvpItems"); - inParams["DataItems"] = ((string[])(DataItems)); - inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyKvpItems", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifyResourceSettings(string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifyResourceSettings"); - inParams["ResourceSettings"] = ((string[])(ResourceSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyResourceSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - ResultingResourceSettings = null; - if ((outParams.Properties["ResultingResourceSettings"] != null && outParams.Properties["ResultingResourceSettings"].Value != null)) - { - int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; - System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); - } - ResultingResourceSettings = arrToRet; - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingResourceSettings = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifyServiceSettings(string SettingData, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifyServiceSettings"); - inParams["SettingData"] = ((string)(SettingData)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyServiceSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint ModifySystemSettings(string SystemSettings, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ModifySystemSettings"); - inParams["SystemSettings"] = ((string)(SystemSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifySystemSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RealizePlannedSystem(System.Management.ManagementPath PlannedSystem, out System.Management.ManagementPath Job, out System.Management.ManagementPath ResultingSystem) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RealizePlannedSystem"); - inParams["PlannedSystem"] = ((System.Management.ManagementPath)(PlannedSystem)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RealizePlannedSystem", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - ResultingSystem = null; - if ((outParams.Properties["ResultingSystem"] != null)) { - ResultingSystem = new System.Management.ManagementPath(outParams.Properties["ResultingSystem"].ToString()); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - ResultingSystem = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RemoveFeatureSettings(System.Management.ManagementPath[] FeatureSettings, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RemoveFeatureSettings"); - if ((FeatureSettings != null)) { - int len = ((System.Array)(FeatureSettings)).Length; - string[] arrProp = new string[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(FeatureSettings)).GetValue(iCounter))).Path; - } - inParams["FeatureSettings"] = arrProp; - } - else { - inParams["FeatureSettings"] = null; - } - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveFeatureSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RemoveFibreChannelChap(string[] FcPortSettings) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RemoveFibreChannelChap"); - inParams["FcPortSettings"] = ((string[])(FcPortSettings)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveFibreChannelChap", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint RemoveKvpItems(string[] DataItems, System.Management.ManagementPath TargetSystem, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RemoveKvpItems"); - inParams["DataItems"] = ((string[])(DataItems)); - inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveKvpItems", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RemoveResourceSettings(System.Management.ManagementPath[] ResourceSettings, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RemoveResourceSettings"); - if ((ResourceSettings != null)) { - int len = ((System.Array)(ResourceSettings)).Length; - string[] arrProp = new string[len]; - for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { - arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(ResourceSettings)).GetValue(iCounter))).Path; - } - inParams["ResourceSettings"] = arrProp; - } - else { - inParams["ResourceSettings"] = null; - } - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveResourceSettings", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); - inParams["RequestedState"] = ((ushort)(RequestedState)); - inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint SetGuestNetworkAdapterConfiguration(System.Management.ManagementPath ComputerSystem, string[] NetworkConfiguration, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("SetGuestNetworkAdapterConfiguration"); - inParams["ComputerSystem"] = ((System.Management.ManagementPath)(ComputerSystem)).Path; - inParams["NetworkConfiguration"] = ((string[])(NetworkConfiguration)); - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetGuestNetworkAdapterConfiguration", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - public uint StartService() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StartService", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint StopService() { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StopService", inParams, null); - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - return System.Convert.ToUInt32(0); - } - } - - public uint ValidatePlannedSystem(System.Management.ManagementPath PlannedSystem, out System.Management.ManagementPath Job) { - if ((isEmbedded == false)) { - System.Management.ManagementBaseObject inParams = null; - inParams = PrivateLateBoundObject.GetMethodParameters("ValidatePlannedSystem"); - inParams["PlannedSystem"] = ((System.Management.ManagementPath)(PlannedSystem)).Path; - System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ValidatePlannedSystem", inParams, null); - Job = null; - if ((outParams.Properties["Job"] != null)) - { - Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); - } - return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); - } - else { - Job = null; - return System.Convert.ToUInt32(0); - } - } - - // Enumerator implementation for enumerating instances of the class. - public class VirtualSystemManagementServiceCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public VirtualSystemManagementServiceCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new VirtualSystemManagementService(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new VirtualSystemManagementServiceEnumerator(privColObj.GetEnumerator()); - } - - public class VirtualSystemManagementServiceEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public VirtualSystemManagementServiceEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new VirtualSystemManagementService(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 +{ + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_VirtualSystemManagementService + public class VirtualSystemManagementService : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + private static string CreatedClassName = "Msvm_VirtualSystemManagementService"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public VirtualSystemManagementService() { + this.InitializeObject(null, null, null); + } + + public VirtualSystemManagementService(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(null, new System.Management.ManagementPath(VirtualSystemManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public VirtualSystemManagementService(System.Management.ManagementScope mgmtScope, string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualSystemManagementService.ConstructPath(keyCreationClassName, keyName, keySystemCreationClassName, keySystemName)), null); + } + + public VirtualSystemManagementService(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public VirtualSystemManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public VirtualSystemManagementService(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public VirtualSystemManagementService(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public VirtualSystemManagementService(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public VirtualSystemManagementService(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] AvailableRequestedStates { + get { + return ((ushort[])(curObj["AvailableRequestedStates"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCommunicationStatusNull { + get { + if ((curObj["CommunicationStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort CommunicationStatus { + get { + if ((curObj["CommunicationStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["CommunicationStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string CreationClassName { + get { + return ((string)(curObj["CreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDetailedStatusNull { + get { + if ((curObj["DetailedStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort DetailedStatus { + get { + if ((curObj["DetailedStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["DetailedStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledDefaultNull { + get { + if ((curObj["EnabledDefault"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledDefault { + get { + if ((curObj["EnabledDefault"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledDefault"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsEnabledStateNull { + get { + if ((curObj["EnabledState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort EnabledState { + get { + if ((curObj["EnabledState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["EnabledState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHealthStateNull { + get { + if ((curObj["HealthState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort HealthState { + get { + if ((curObj["HealthState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["HealthState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsInstallDateNull { + get { + if ((curObj["InstallDate"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime InstallDate { + get { + if ((curObj["InstallDate"] != null)) { + return ToDateTime(((string)(curObj["InstallDate"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Name { + get { + return ((string)(curObj["Name"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsOperatingStatusNull { + get { + if ((curObj["OperatingStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort OperatingStatus { + get { + if ((curObj["OperatingStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["OperatingStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ushort[] OperationalStatus { + get { + return ((ushort[])(curObj["OperationalStatus"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OtherEnabledState { + get { + return ((string)(curObj["OtherEnabledState"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerContact { + get { + return ((string)(curObj["PrimaryOwnerContact"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string PrimaryOwnerName { + get { + return ((string)(curObj["PrimaryOwnerName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsPrimaryStatusNull { + get { + if ((curObj["PrimaryStatus"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort PrimaryStatus { + get { + if ((curObj["PrimaryStatus"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["PrimaryStatus"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsRequestedStateNull { + get { + if ((curObj["RequestedState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort RequestedState { + get { + if ((curObj["RequestedState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["RequestedState"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsStartedNull { + get { + if ((curObj["Started"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool Started { + get { + if ((curObj["Started"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["Started"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string StartMode { + get { + return ((string)(curObj["StartMode"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Status { + get { + return ((string)(curObj["Status"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] StatusDescriptions { + get { + return ((string[])(curObj["StatusDescriptions"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemCreationClassName { + get { + return ((string)(curObj["SystemCreationClassName"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SystemName { + get { + return ((string)(curObj["SystemName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTimeOfLastStateChangeNull { + get { + if ((curObj["TimeOfLastStateChange"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime TimeOfLastStateChange { + get { + if ((curObj["TimeOfLastStateChange"] != null)) { + return ToDateTime(((string)(curObj["TimeOfLastStateChange"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsTransitioningToStateNull { + get { + if ((curObj["TransitioningToState"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort TransitioningToState { + get { + if ((curObj["TransitioningToState"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["TransitioningToState"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeCommunicationStatus() { + if ((this.IsCommunicationStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDetailedStatus() { + if ((this.IsDetailedStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledDefault() { + if ((this.IsEnabledDefaultNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeEnabledState() { + if ((this.IsEnabledStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeHealthState() { + if ((this.IsHealthStateNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeInstallDate() { + if ((this.IsInstallDateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeOperatingStatus() { + if ((this.IsOperatingStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializePrimaryStatus() { + if ((this.IsPrimaryStatusNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeRequestedState() { + if ((this.IsRequestedStateNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeStarted() { + if ((this.IsStartedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTimeOfLastStateChange() { + if ((this.IsTimeOfLastStateChangeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeTransitioningToState() { + if ((this.IsTransitioningToStateNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyCreationClassName, string keyName, string keySystemCreationClassName, string keySystemName) { + string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualSystemManagementService"; + strPath = string.Concat(strPath, string.Concat(".CreationClassName=", string.Concat("\"", string.Concat(keyCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",Name=", string.Concat("\"", string.Concat(keyName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemCreationClassName=", string.Concat("\"", string.Concat(keySystemCreationClassName, "\"")))); + strPath = string.Concat(strPath, string.Concat(",SystemName=", string.Concat("\"", string.Concat(keySystemName, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static VirtualSystemManagementServiceCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static VirtualSystemManagementServiceCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static VirtualSystemManagementServiceCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static VirtualSystemManagementServiceCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_VirtualSystemManagementService"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new VirtualSystemManagementServiceCollection(clsObject.GetInstances(enumOptions)); + } + + public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static VirtualSystemManagementServiceCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualSystemManagementService", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new VirtualSystemManagementServiceCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static VirtualSystemManagementService CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new VirtualSystemManagementService(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public uint AddFeatureSettings(System.Management.ManagementPath AffectedConfiguration, string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("AddFeatureSettings"); + inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; + inParams["FeatureSettings"] = ((string[])(FeatureSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddFeatureSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + ResultingFeatureSettings = null; + if ((outParams.Properties["ResultingFeatureSettings"] != null && outParams.Properties["ResultingFeatureSettings"].Value != null)) + { + int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingFeatureSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingFeatureSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint AddFibreChannelChap(string[] FcPortSettings, byte SecretEncoding, byte[] SharedSecret) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("AddFibreChannelChap"); + inParams["FcPortSettings"] = ((string[])(FcPortSettings)); + inParams["SecretEncoding"] = ((byte)(SecretEncoding)); + inParams["SharedSecret"] = ((byte[])(SharedSecret)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddFibreChannelChap", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint AddKvpItems(string[] DataItems, System.Management.ManagementPath TargetSystem, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("AddKvpItems"); + inParams["DataItems"] = ((string[])(DataItems)); + inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddKvpItems", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint AddResourceSettings(System.Management.ManagementPath AffectedConfiguration, string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("AddResourceSettings"); + inParams["AffectedConfiguration"] = ((System.Management.ManagementPath)(AffectedConfiguration)).Path; + inParams["ResourceSettings"] = ((string[])(ResourceSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("AddResourceSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + ResultingResourceSettings = null; + if ((outParams.Properties["ResultingResourceSettings"] != null && outParams.Properties["ResultingResourceSettings"].Value != null)) + { + int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingResourceSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingResourceSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint DefineSystem(string ReferenceConfigurationPath, string[] ResourceSettings, string SystemSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath ResultingSystem) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("DefineSystem"); + inParams["ReferenceConfiguration"] = ReferenceConfigurationPath; + inParams["ResourceSettings"] = ResourceSettings; + inParams["SystemSettings"] = SystemSettings; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DefineSystem", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + ResultingSystem = null; + if ((outParams.Properties["ResultingSystem"] != null && outParams.Properties["ResultingSystem"].Value != null)) + { + ResultingSystem = new System.Management.ManagementPath((string)outParams.Properties["ResultingSystem"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingSystem = null; + return System.Convert.ToUInt32(0); + } + } + + public uint DestroySystem(System.Management.ManagementPath AffectedSystem, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("DestroySystem"); + inParams["AffectedSystem"] = ((System.Management.ManagementPath)(AffectedSystem)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DestroySystem", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ExportSystemDefinition(System.Management.ManagementPath ComputerSystem, string ExportDirectory, string ExportSettingData, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ExportSystemDefinition"); + inParams["ComputerSystem"] = ((System.Management.ManagementPath)(ComputerSystem)).Path; + inParams["ExportDirectory"] = ((string)(ExportDirectory)); + inParams["ExportSettingData"] = ((string)(ExportSettingData)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ExportSystemDefinition", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint FormatError(string[] Errors, out string ErrorMessage) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("FormatError"); + inParams["Errors"] = ((string[])(Errors)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("FormatError", inParams, null); + ErrorMessage = System.Convert.ToString(outParams.Properties["ErrorMessage"].Value); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + ErrorMessage = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GenerateWwpn(uint NumberOfWwpns, out string[] GeneratedWwpn) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("GenerateWwpn"); + inParams["NumberOfWwpns"] = ((uint)(NumberOfWwpns)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GenerateWwpn", inParams, null); + GeneratedWwpn = ((string[])(outParams.Properties["GeneratedWwpn"].Value)); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + GeneratedWwpn = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GetCurrentWwpnFromGenerator(out string CurrentWwpn) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetCurrentWwpnFromGenerator", inParams, null); + CurrentWwpn = System.Convert.ToString(outParams.Properties["CurrentWwpn"].Value); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + CurrentWwpn = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GetDefinitionFileSummaryInformation(string[] DefinitionFiles, out System.Management.ManagementBaseObject[] SummaryInformation) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("GetDefinitionFileSummaryInformation"); + inParams["DefinitionFiles"] = ((string[])(DefinitionFiles)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetDefinitionFileSummaryInformation", inParams, null); + SummaryInformation = ((System.Management.ManagementBaseObject[])(outParams.Properties["SummaryInformation"].Value)); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + SummaryInformation = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GetSizeOfSystemFiles(System.Management.ManagementPath Vssd, out ulong Size) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("GetSizeOfSystemFiles"); + inParams["Vssd"] = ((System.Management.ManagementPath)(Vssd)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetSizeOfSystemFiles", inParams, null); + Size = System.Convert.ToUInt64(outParams.Properties["Size"].Value); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Size = System.Convert.ToUInt64(0); + return System.Convert.ToUInt32(0); + } + } + + public uint GetSummaryInformation(uint[] RequestedInformation, System.Management.ManagementPath[] SettingData, out System.Management.ManagementBaseObject[] SummaryInformation) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("GetSummaryInformation"); + inParams["RequestedInformation"] = ((uint[])(RequestedInformation)); + if ((SettingData != null)) { + int len = ((System.Array)(SettingData)).Length; + string[] arrProp = new string[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(SettingData)).GetValue(iCounter))).Path; + } + inParams["SettingData"] = arrProp; + } + else { + inParams["SettingData"] = null; + } + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetSummaryInformation", inParams, null); + SummaryInformation = ((System.Management.ManagementBaseObject[])(outParams.Properties["SummaryInformation"].Value)); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + SummaryInformation = null; + return System.Convert.ToUInt32(0); + } + } + + public uint GetVirtualSystemThumbnailImage(ushort HeightPixels, System.Management.ManagementPath TargetSystem, ushort WidthPixels, out byte[] ImageData) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("GetVirtualSystemThumbnailImage"); + inParams["HeightPixels"] = ((ushort)(HeightPixels)); + inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; + inParams["WidthPixels"] = ((ushort)(WidthPixels)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetVirtualSystemThumbnailImage", inParams, null); + ImageData = ((byte[])(outParams.Properties["ImageData"].Value)); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + ImageData = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ImportSnapshotDefinitions(System.Management.ManagementPath PlannedSystem, string SnapshotFolder, out System.Management.ManagementPath[] ImportedSnapshots, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ImportSnapshotDefinitions"); + inParams["PlannedSystem"] = ((System.Management.ManagementPath)(PlannedSystem)).Path; + inParams["SnapshotFolder"] = ((string)(SnapshotFolder)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ImportSnapshotDefinitions", inParams, null); + ImportedSnapshots = null; + if ((outParams.Properties["ImportedSnapshots"] != null && outParams.Properties["ImportedSnapshots"].Value != null)) + { + int len = ((System.Array)(outParams.Properties["ImportedSnapshots"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ImportedSnapshots"].Value)).GetValue(iCounter).ToString()); + } + ImportedSnapshots = arrToRet; + } + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + ImportedSnapshots = null; + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ImportSystemDefinition(bool GenerateNewSystemIdentifier, string SnapshotFolder, string SystemDefinitionFile, out System.Management.ManagementPath ImportedSystem, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ImportSystemDefinition"); + inParams["GenerateNewSystemIdentifier"] = ((bool)(GenerateNewSystemIdentifier)); + inParams["SnapshotFolder"] = ((string)(SnapshotFolder)); + inParams["SystemDefinitionFile"] = ((string)(SystemDefinitionFile)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ImportSystemDefinition", inParams, null); + ImportedSystem = null; + if ((outParams.Properties["ImportedSystem"] != null && outParams.Properties["ImportedSystem"].Value != null)) + { + ImportedSystem = new System.Management.ManagementPath(outParams.Properties["ImportedSystem"].ToString()); + } + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + ImportedSystem = null; + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifyDiskMergeSettings(string SettingData, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifyDiskMergeSettings"); + inParams["SettingData"] = ((string)(SettingData)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyDiskMergeSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifyFeatureSettings(string[] FeatureSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingFeatureSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifyFeatureSettings"); + inParams["FeatureSettings"] = ((string[])(FeatureSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyFeatureSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + ResultingFeatureSettings = null; + if ((outParams.Properties["ResultingFeatureSettings"] != null && outParams.Properties["ResultingFeatureSettings"].Value != null)) + { + int len = ((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingFeatureSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingFeatureSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingFeatureSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifyKvpItems(string[] DataItems, System.Management.ManagementPath TargetSystem, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifyKvpItems"); + inParams["DataItems"] = ((string[])(DataItems)); + inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyKvpItems", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifyResourceSettings(string[] ResourceSettings, out System.Management.ManagementPath Job, out System.Management.ManagementPath[] ResultingResourceSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifyResourceSettings"); + inParams["ResourceSettings"] = ((string[])(ResourceSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyResourceSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null) && outParams.Properties["Job"].Value != null) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + ResultingResourceSettings = null; + if ((outParams.Properties["ResultingResourceSettings"] != null && outParams.Properties["ResultingResourceSettings"].Value != null)) + { + int len = ((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).Length; + System.Management.ManagementPath[] arrToRet = new System.Management.ManagementPath[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrToRet[iCounter] = new System.Management.ManagementPath(((System.Array)(outParams.Properties["ResultingResourceSettings"].Value)).GetValue(iCounter).ToString()); + } + ResultingResourceSettings = arrToRet; + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingResourceSettings = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifyServiceSettings(string SettingData, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifyServiceSettings"); + inParams["SettingData"] = ((string)(SettingData)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifyServiceSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint ModifySystemSettings(string SystemSettings, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ModifySystemSettings"); + inParams["SystemSettings"] = ((string)(SystemSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ModifySystemSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RealizePlannedSystem(System.Management.ManagementPath PlannedSystem, out System.Management.ManagementPath Job, out System.Management.ManagementPath ResultingSystem) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RealizePlannedSystem"); + inParams["PlannedSystem"] = ((System.Management.ManagementPath)(PlannedSystem)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RealizePlannedSystem", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + ResultingSystem = null; + if ((outParams.Properties["ResultingSystem"] != null)) { + ResultingSystem = new System.Management.ManagementPath(outParams.Properties["ResultingSystem"].ToString()); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + ResultingSystem = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RemoveFeatureSettings(System.Management.ManagementPath[] FeatureSettings, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RemoveFeatureSettings"); + if ((FeatureSettings != null)) { + int len = ((System.Array)(FeatureSettings)).Length; + string[] arrProp = new string[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(FeatureSettings)).GetValue(iCounter))).Path; + } + inParams["FeatureSettings"] = arrProp; + } + else { + inParams["FeatureSettings"] = null; + } + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveFeatureSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RemoveFibreChannelChap(string[] FcPortSettings) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RemoveFibreChannelChap"); + inParams["FcPortSettings"] = ((string[])(FcPortSettings)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveFibreChannelChap", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint RemoveKvpItems(string[] DataItems, System.Management.ManagementPath TargetSystem, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RemoveKvpItems"); + inParams["DataItems"] = ((string[])(DataItems)); + inParams["TargetSystem"] = ((System.Management.ManagementPath)(TargetSystem)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveKvpItems", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RemoveResourceSettings(System.Management.ManagementPath[] ResourceSettings, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RemoveResourceSettings"); + if ((ResourceSettings != null)) { + int len = ((System.Array)(ResourceSettings)).Length; + string[] arrProp = new string[len]; + for (int iCounter = 0; (iCounter < len); iCounter = (iCounter + 1)) { + arrProp[iCounter] = ((System.Management.ManagementPath)(((System.Array)(ResourceSettings)).GetValue(iCounter))).Path; + } + inParams["ResourceSettings"] = arrProp; + } + else { + inParams["ResourceSettings"] = null; + } + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RemoveResourceSettings", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint RequestStateChange(ushort RequestedState, System.DateTime TimeoutPeriod, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("RequestStateChange"); + inParams["RequestedState"] = ((ushort)(RequestedState)); + inParams["TimeoutPeriod"] = ToDmtfDateTime(((System.DateTime)(TimeoutPeriod))); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("RequestStateChange", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint SetGuestNetworkAdapterConfiguration(System.Management.ManagementPath ComputerSystem, string[] NetworkConfiguration, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("SetGuestNetworkAdapterConfiguration"); + inParams["ComputerSystem"] = ((System.Management.ManagementPath)(ComputerSystem)).Path; + inParams["NetworkConfiguration"] = ((string[])(NetworkConfiguration)); + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetGuestNetworkAdapterConfiguration", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + public uint StartService() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StartService", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint StopService() { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("StopService", inParams, null); + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + return System.Convert.ToUInt32(0); + } + } + + public uint ValidatePlannedSystem(System.Management.ManagementPath PlannedSystem, out System.Management.ManagementPath Job) { + if ((isEmbedded == false)) { + System.Management.ManagementBaseObject inParams = null; + inParams = PrivateLateBoundObject.GetMethodParameters("ValidatePlannedSystem"); + inParams["PlannedSystem"] = ((System.Management.ManagementPath)(PlannedSystem)).Path; + System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("ValidatePlannedSystem", inParams, null); + Job = null; + if ((outParams.Properties["Job"] != null)) + { + Job = new System.Management.ManagementPath((string)outParams.Properties["Job"].Value); + } + return System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value); + } + else { + Job = null; + return System.Convert.ToUInt32(0); + } + } + + // Enumerator implementation for enumerating instances of the class. + public class VirtualSystemManagementServiceCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public VirtualSystemManagementServiceCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new VirtualSystemManagementService(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new VirtualSystemManagementServiceEnumerator(privColObj.GetEnumerator()); + } + + public class VirtualSystemManagementServiceEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public VirtualSystemManagementServiceEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new VirtualSystemManagementService(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementServiceSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementServiceSettingData.cs index 98f0eff63834..7347df9b0959 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementServiceSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemManagementServiceSettingData.cs @@ -1,809 +1,809 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 -{ - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // An Early Bound class generated for the WMI class.Msvm_VirtualSystemManagementServiceSettingData - public class VirtualSystemManagementServiceSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_VirtualSystemManagementServiceSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public VirtualSystemManagementServiceSettingData() { - this.InitializeObject(null, null, null); - } - - public VirtualSystemManagementServiceSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(VirtualSystemManagementServiceSettingData.ConstructPath(keyInstanceID)), null); - } - - public VirtualSystemManagementServiceSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualSystemManagementServiceSettingData.ConstructPath(keyInstanceID)), null); - } - - public VirtualSystemManagementServiceSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public VirtualSystemManagementServiceSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public VirtualSystemManagementServiceSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public VirtualSystemManagementServiceSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public VirtualSystemManagementServiceSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public VirtualSystemManagementServiceSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"Used by OEMs to allow BIOS-locked Windows operating systems to run in the virtual machine. This string must be exactly 32 characters in length. -This is a read-only property, but it can be changed using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] - public string BiosLockString { - get { - return ((string)(curObj["BiosLockString"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The WorldWideNodeName address for dynamically generated WorldWideName addresses u" + - "sed for Synthetic HBAs.\nThis is a read-only property, but it can be changed usin" + - "g the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService cl" + - "ass.")] - public string CurrentWWNNAddress { - get { - return ((string)(curObj["CurrentWWNNAddress"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The default external data root. By default, \"root\\ProgramData\\Microsoft\\Windows\\V" + - "irtualization\".\nThis is a read-only property, but it can be changed using the Mo" + - "difyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] - public string DefaultExternalDataRoot { - get { - return ((string)(curObj["DefaultExternalDataRoot"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The default virtual hard disk path. By default, \"root\\Users\\Public\\Documents\\Virt" + - "ual Hard Disks\".\nThis is a read-only property, but it can be changed using the M" + - "odifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] - public string DefaultVirtualHardDiskPath { - get { - return ((string)(curObj["DefaultVirtualHardDiskPath"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsHbaLunTimeoutNull { - get { - if ((curObj["HbaLunTimeout"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"This property describes the amount of time that the Synthetic FC virtual device will wait for a LUN to appear before starting a virtual machine. -This is a read-only property, but it can be changed using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint HbaLunTimeout { - get { - if ((curObj["HbaLunTimeout"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["HbaLunTimeout"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum MAC address for dynamically generated MAC addresses.\nThis is a read-o" + - "nly property, but it can be changed using the ModifyServiceSettings method of th" + - "e Msvm_VirtualSystemManagementService class.")] - public string MaximumMacAddress { - get { - return ((string)(curObj["MaximumMacAddress"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The maximum WorldWidePortName address for dynamically generated WorldWideName add" + - "resses used for Synthetic HBAs.\nThis is a read-only property, but it can be chan" + - "ged using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementSe" + - "rvice class.")] - public string MaximumWWPNAddress { - get { - return ((string)(curObj["MaximumWWPNAddress"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The minimum MAC address for dynamically generated MAC addresses.\nThis is a read-o" + - "nly property, but it can be changed using the ModifyServiceSettings method of th" + - "e Msvm_VirtualSystemManagementService class.")] - public string MinimumMacAddress { - get { - return ((string)(curObj["MinimumMacAddress"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The minimum WorldWidePortName address for dynamically generated WorldWideName add" + - "resses used for Synthetic HBAs.\nThis is a read-only property, but it can be chan" + - "ged using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementSe" + - "rvice class.")] - public string MinimumWWPNAddress { - get { - return ((string)(curObj["MinimumWWPNAddress"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsNumaSpanningEnabledNull { - get { - if ((curObj["NumaSpanningEnabled"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Reserved for future use.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool NumaSpanningEnabled { - get { - if ((curObj["NumaSpanningEnabled"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["NumaSpanningEnabled"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Controls memory allocation for the VMs on non-uniform memory access (NUMA) system" + - "s.\nThis is a read-only property, but it can be changed using the ModifyServiceSe" + - "ttings method of the Msvm_VirtualSystemManagementService class.")] - public string PrimaryOwnerContact { - get { - return ((string)(curObj["PrimaryOwnerContact"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description(@"Describes how the primary system owner can be reached (for example, phone number or e-mail address). By default, empty. This name may not exceed 256 characters in length. -This is a read-only property, but it can be changed using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] - public string PrimaryOwnerName { - get { - return ((string)(curObj["PrimaryOwnerName"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private bool ShouldSerializeHbaLunTimeout() { - if ((this.IsHbaLunTimeoutNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeNumaSpanningEnabled() { - if ((this.IsNumaSpanningEnabledNull == false)) { - return true; - } - return false; - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualSystemManagementServiceSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static VirtualSystemManagementServiceSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static VirtualSystemManagementServiceSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static VirtualSystemManagementServiceSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static VirtualSystemManagementServiceSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_VirtualSystemManagementServiceSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new VirtualSystemManagementServiceSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualSystemManagementServiceSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new VirtualSystemManagementServiceSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static VirtualSystemManagementServiceSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new VirtualSystemManagementServiceSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - // Enumerator implementation for enumerating instances of the class. - public class VirtualSystemManagementServiceSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public VirtualSystemManagementServiceSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new VirtualSystemManagementServiceSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new VirtualSystemManagementServiceSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class VirtualSystemManagementServiceSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public VirtualSystemManagementServiceSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new VirtualSystemManagementServiceSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 +{ + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // An Early Bound class generated for the WMI class.Msvm_VirtualSystemManagementServiceSettingData + public class VirtualSystemManagementServiceSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_VirtualSystemManagementServiceSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public VirtualSystemManagementServiceSettingData() { + this.InitializeObject(null, null, null); + } + + public VirtualSystemManagementServiceSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(VirtualSystemManagementServiceSettingData.ConstructPath(keyInstanceID)), null); + } + + public VirtualSystemManagementServiceSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualSystemManagementServiceSettingData.ConstructPath(keyInstanceID)), null); + } + + public VirtualSystemManagementServiceSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public VirtualSystemManagementServiceSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public VirtualSystemManagementServiceSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public VirtualSystemManagementServiceSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public VirtualSystemManagementServiceSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public VirtualSystemManagementServiceSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"Used by OEMs to allow BIOS-locked Windows operating systems to run in the virtual machine. This string must be exactly 32 characters in length. +This is a read-only property, but it can be changed using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] + public string BiosLockString { + get { + return ((string)(curObj["BiosLockString"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The WorldWideNodeName address for dynamically generated WorldWideName addresses u" + + "sed for Synthetic HBAs.\nThis is a read-only property, but it can be changed usin" + + "g the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService cl" + + "ass.")] + public string CurrentWWNNAddress { + get { + return ((string)(curObj["CurrentWWNNAddress"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The default external data root. By default, \"root\\ProgramData\\Microsoft\\Windows\\V" + + "irtualization\".\nThis is a read-only property, but it can be changed using the Mo" + + "difyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] + public string DefaultExternalDataRoot { + get { + return ((string)(curObj["DefaultExternalDataRoot"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The default virtual hard disk path. By default, \"root\\Users\\Public\\Documents\\Virt" + + "ual Hard Disks\".\nThis is a read-only property, but it can be changed using the M" + + "odifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] + public string DefaultVirtualHardDiskPath { + get { + return ((string)(curObj["DefaultVirtualHardDiskPath"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsHbaLunTimeoutNull { + get { + if ((curObj["HbaLunTimeout"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"This property describes the amount of time that the Synthetic FC virtual device will wait for a LUN to appear before starting a virtual machine. +This is a read-only property, but it can be changed using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint HbaLunTimeout { + get { + if ((curObj["HbaLunTimeout"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["HbaLunTimeout"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum MAC address for dynamically generated MAC addresses.\nThis is a read-o" + + "nly property, but it can be changed using the ModifyServiceSettings method of th" + + "e Msvm_VirtualSystemManagementService class.")] + public string MaximumMacAddress { + get { + return ((string)(curObj["MaximumMacAddress"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The maximum WorldWidePortName address for dynamically generated WorldWideName add" + + "resses used for Synthetic HBAs.\nThis is a read-only property, but it can be chan" + + "ged using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementSe" + + "rvice class.")] + public string MaximumWWPNAddress { + get { + return ((string)(curObj["MaximumWWPNAddress"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The minimum MAC address for dynamically generated MAC addresses.\nThis is a read-o" + + "nly property, but it can be changed using the ModifyServiceSettings method of th" + + "e Msvm_VirtualSystemManagementService class.")] + public string MinimumMacAddress { + get { + return ((string)(curObj["MinimumMacAddress"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The minimum WorldWidePortName address for dynamically generated WorldWideName add" + + "resses used for Synthetic HBAs.\nThis is a read-only property, but it can be chan" + + "ged using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementSe" + + "rvice class.")] + public string MinimumWWPNAddress { + get { + return ((string)(curObj["MinimumWWPNAddress"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsNumaSpanningEnabledNull { + get { + if ((curObj["NumaSpanningEnabled"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Reserved for future use.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool NumaSpanningEnabled { + get { + if ((curObj["NumaSpanningEnabled"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["NumaSpanningEnabled"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Controls memory allocation for the VMs on non-uniform memory access (NUMA) system" + + "s.\nThis is a read-only property, but it can be changed using the ModifyServiceSe" + + "ttings method of the Msvm_VirtualSystemManagementService class.")] + public string PrimaryOwnerContact { + get { + return ((string)(curObj["PrimaryOwnerContact"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description(@"Describes how the primary system owner can be reached (for example, phone number or e-mail address). By default, empty. This name may not exceed 256 characters in length. +This is a read-only property, but it can be changed using the ModifyServiceSettings method of the Msvm_VirtualSystemManagementService class.")] + public string PrimaryOwnerName { + get { + return ((string)(curObj["PrimaryOwnerName"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private bool ShouldSerializeHbaLunTimeout() { + if ((this.IsHbaLunTimeoutNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeNumaSpanningEnabled() { + if ((this.IsNumaSpanningEnabledNull == false)) { + return true; + } + return false; + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualSystemManagementServiceSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static VirtualSystemManagementServiceSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static VirtualSystemManagementServiceSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static VirtualSystemManagementServiceSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static VirtualSystemManagementServiceSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_VirtualSystemManagementServiceSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new VirtualSystemManagementServiceSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static VirtualSystemManagementServiceSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualSystemManagementServiceSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new VirtualSystemManagementServiceSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static VirtualSystemManagementServiceSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new VirtualSystemManagementServiceSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + // Enumerator implementation for enumerating instances of the class. + public class VirtualSystemManagementServiceSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public VirtualSystemManagementServiceSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new VirtualSystemManagementServiceSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new VirtualSystemManagementServiceSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class VirtualSystemManagementServiceSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public VirtualSystemManagementServiceSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new VirtualSystemManagementServiceSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemSettingData.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemSettingData.cs index 85babfee2eb8..1dab7d0f8116 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemSettingData.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/WmiWrappers/ROOT.virtualization.v2.Msvm_VirtualSystemSettingData.cs @@ -15,517 +15,517 @@ // specific language governing permissions and limitations // under the License. -namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { - using System; - using System.ComponentModel; - using System.Management; - using System.Collections; - using System.Globalization; - using System.ComponentModel.Design.Serialization; - using System.Reflection; - - - // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. - // Functions IsNull() are used to check if a property is NULL. - // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. - // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. - // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. - // An Early Bound class generated for the WMI class.Msvm_VirtualSystemSettingData - public class VirtualSystemSettingData : System.ComponentModel.Component { - - // Private property to hold the WMI namespace in which the class resides. - private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; - - // Private property to hold the name of WMI class which created this class. - public static string CreatedClassName = "Msvm_VirtualSystemSettingData"; - - // Private member variable to hold the ManagementScope which is used by the various methods. - private static System.Management.ManagementScope statMgmtScope = null; - - private ManagementSystemProperties PrivateSystemProperties; - - // Underlying lateBound WMI object. - private System.Management.ManagementObject PrivateLateBoundObject; - - // Member variable to store the 'automatic commit' behavior for the class. - private bool AutoCommitProp; - - // Private variable to hold the embedded property representing the instance. - private System.Management.ManagementBaseObject embeddedObj; - - // The current WMI object used - private System.Management.ManagementBaseObject curObj; - - // Flag to indicate if the instance is an embedded object. - private bool isEmbedded; - - // Below are different overloads of constructors to initialize an instance of the class with a WMI object. - public VirtualSystemSettingData() { - this.InitializeObject(null, null, null); - } - - public VirtualSystemSettingData(string keyInstanceID) { - this.InitializeObject(null, new System.Management.ManagementPath(VirtualSystemSettingData.ConstructPath(keyInstanceID)), null); - } - - public VirtualSystemSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { - this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualSystemSettingData.ConstructPath(keyInstanceID)), null); - } - - public VirtualSystemSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(null, path, getOptions); - } - - public VirtualSystemSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { - this.InitializeObject(mgmtScope, path, null); - } - - public VirtualSystemSettingData(System.Management.ManagementPath path) { - this.InitializeObject(null, path, null); - } - - public VirtualSystemSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - this.InitializeObject(mgmtScope, path, getOptions); - } - - public VirtualSystemSettingData(System.Management.ManagementObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - PrivateLateBoundObject = theObject; - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - public VirtualSystemSettingData(System.Management.ManagementBaseObject theObject) { - Initialize(); - if ((CheckIfProperClass(theObject) == true)) { - embeddedObj = theObject; - PrivateSystemProperties = new ManagementSystemProperties(theObject); - curObj = embeddedObj; - isEmbedded = true; - } - else { - throw new System.ArgumentException("Class name does not match."); - } - } - - // Property returns the namespace of the WMI class. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string OriginatingNamespace { - get { - return "ROOT\\virtualization\\v2"; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ManagementClassName { - get { - string strRet = CreatedClassName; - if ((curObj != null)) { - if ((curObj.ClassPath != null)) { - strRet = ((string)(curObj["__CLASS"])); - if (((strRet == null) - || (strRet == string.Empty))) { - strRet = CreatedClassName; - } - } - } - return strRet; - } - } - - // Property pointing to an embedded object to get System properties of the WMI object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public ManagementSystemProperties SystemProperties { - get { - return PrivateSystemProperties; - } - } - - // Property returning the underlying lateBound object. - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementBaseObject LateBoundObject { - get { - return curObj; - } - } - - // ManagementScope of the object. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public System.Management.ManagementScope Scope { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Scope; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Scope = value; - } - } - } - - // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool AutoCommit { - get { - return AutoCommitProp; - } - set { - AutoCommitProp = value; - } - } - - // The ManagementPath of the underlying WMI object. - [Browsable(true)] - public System.Management.ManagementPath Path { - get { - if ((isEmbedded == false)) { - return PrivateLateBoundObject.Path; - } - else { - return null; - } - } - set { - if ((isEmbedded == false)) { - if ((CheckIfProperClass(null, value, null) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - PrivateLateBoundObject.Path = value; - } - } - } - - // Public static scope property which is used by the various methods. - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public static System.Management.ManagementScope StaticScope { - get { - return statMgmtScope; - } - set { - statMgmtScope = value; - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +namespace CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2 { + using System; + using System.ComponentModel; + using System.Management; + using System.Collections; + using System.Globalization; + using System.ComponentModel.Design.Serialization; + using System.Reflection; + + + // Functions ShouldSerialize are functions used by VS property browser to check if a particular property has to be serialized. These functions are added for all ValueType properties ( properties of type Int32, BOOL etc.. which cannot be set to null). These functions use IsNull function. These functions are also used in the TypeConverter implementation for the properties to check for NULL value of property so that an empty value can be shown in Property browser in case of Drag and Drop in Visual studio. + // Functions IsNull() are used to check if a property is NULL. + // Functions Reset are added for Nullable Read/Write properties. These functions are used by VS designer in property browser to set a property to NULL. + // Every property added to the class for WMI property has attributes set to define its behavior in Visual Studio designer and also to define a TypeConverter to be used. + // Datetime conversion functions ToDateTime and ToDmtfDateTime are added to the class to convert DMTF datetime to System.DateTime and vice-versa. + // An Early Bound class generated for the WMI class.Msvm_VirtualSystemSettingData + public class VirtualSystemSettingData : System.ComponentModel.Component { + + // Private property to hold the WMI namespace in which the class resides. + private static string CreatedWmiNamespace = "ROOT\\virtualization\\v2"; + + // Private property to hold the name of WMI class which created this class. + public static string CreatedClassName = "Msvm_VirtualSystemSettingData"; + + // Private member variable to hold the ManagementScope which is used by the various methods. + private static System.Management.ManagementScope statMgmtScope = null; + + private ManagementSystemProperties PrivateSystemProperties; + + // Underlying lateBound WMI object. + private System.Management.ManagementObject PrivateLateBoundObject; + + // Member variable to store the 'automatic commit' behavior for the class. + private bool AutoCommitProp; + + // Private variable to hold the embedded property representing the instance. + private System.Management.ManagementBaseObject embeddedObj; + + // The current WMI object used + private System.Management.ManagementBaseObject curObj; + + // Flag to indicate if the instance is an embedded object. + private bool isEmbedded; + + // Below are different overloads of constructors to initialize an instance of the class with a WMI object. + public VirtualSystemSettingData() { + this.InitializeObject(null, null, null); + } + + public VirtualSystemSettingData(string keyInstanceID) { + this.InitializeObject(null, new System.Management.ManagementPath(VirtualSystemSettingData.ConstructPath(keyInstanceID)), null); + } + + public VirtualSystemSettingData(System.Management.ManagementScope mgmtScope, string keyInstanceID) { + this.InitializeObject(((System.Management.ManagementScope)(mgmtScope)), new System.Management.ManagementPath(VirtualSystemSettingData.ConstructPath(keyInstanceID)), null); + } + + public VirtualSystemSettingData(System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(null, path, getOptions); + } + + public VirtualSystemSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path) { + this.InitializeObject(mgmtScope, path, null); + } + + public VirtualSystemSettingData(System.Management.ManagementPath path) { + this.InitializeObject(null, path, null); + } + + public VirtualSystemSettingData(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + this.InitializeObject(mgmtScope, path, getOptions); + } + + public VirtualSystemSettingData(System.Management.ManagementObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + PrivateLateBoundObject = theObject; + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + public VirtualSystemSettingData(System.Management.ManagementBaseObject theObject) { + Initialize(); + if ((CheckIfProperClass(theObject) == true)) { + embeddedObj = theObject; + PrivateSystemProperties = new ManagementSystemProperties(theObject); + curObj = embeddedObj; + isEmbedded = true; + } + else { + throw new System.ArgumentException("Class name does not match."); + } + } + + // Property returns the namespace of the WMI class. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string OriginatingNamespace { + get { + return "ROOT\\virtualization\\v2"; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ManagementClassName { + get { + string strRet = CreatedClassName; + if ((curObj != null)) { + if ((curObj.ClassPath != null)) { + strRet = ((string)(curObj["__CLASS"])); + if (((strRet == null) + || (strRet == string.Empty))) { + strRet = CreatedClassName; + } + } + } + return strRet; + } + } + + // Property pointing to an embedded object to get System properties of the WMI object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ManagementSystemProperties SystemProperties { + get { + return PrivateSystemProperties; + } + } + + // Property returning the underlying lateBound object. + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementBaseObject LateBoundObject { + get { + return curObj; + } + } + + // ManagementScope of the object. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public System.Management.ManagementScope Scope { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Scope; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Scope = value; + } + } + } + + // Property to show the commit behavior for the WMI object. If true, WMI object will be automatically saved after each property modification.(ie. Put() is called after modification of a property). + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool AutoCommit { + get { + return AutoCommitProp; + } + set { + AutoCommitProp = value; + } + } + + // The ManagementPath of the underlying WMI object. + [Browsable(true)] + public System.Management.ManagementPath Path { + get { + if ((isEmbedded == false)) { + return PrivateLateBoundObject.Path; + } + else { + return null; + } + } + set { + if ((isEmbedded == false)) { + if ((CheckIfProperClass(null, value, null) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + PrivateLateBoundObject.Path = value; + } + } + } + + // Public static scope property which is used by the various methods. + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public static System.Management.ManagementScope StaticScope { + get { + return statMgmtScope; + } + set { + statMgmtScope = value; + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"Any additional information provided to the recovery action. The meaning of this property is defined by the action in AutomaticRecoveryAction. If AutomaticRecoveryAction is 0 (""None"") or 1 (""Restart""), this value is NULL. If AutomaticRecoveryAction is 2 (""Revert to Snapshot""), this is the object path to a snapshot that should be applied on failure of the virtual machine worker process. -This is a read-only property, but it can be changed using the ModifyVirtualSystem method of the Msvm_VirtualSystemManagementService class.")] - public string AdditionalRecoveryInformation { - get { - return ((string)(curObj["AdditionalRecoveryInformation"])); - } - set { - curObj["AdditionalRecoveryInformation"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAllowFullSCSICommandSetNull { - get { - if ((curObj["AllowFullSCSICommandSet"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +This is a read-only property, but it can be changed using the ModifyVirtualSystem method of the Msvm_VirtualSystemManagementService class.")] + public string AdditionalRecoveryInformation { + get { + return ((string)(curObj["AdditionalRecoveryInformation"])); + } + set { + curObj["AdditionalRecoveryInformation"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAllowFullSCSICommandSetNull { + get { + if ((curObj["AllowFullSCSICommandSet"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"Indicates whether SCSI commands from the guest operating system are passed to pass-through disks. If TRUE, SCSI commands emitted by the guest operating system to pass-through disks are not filtered.It is recommended that SCSI filtering remains enabled for production deployments. This is a read-only property, but it can be changed using the ModifyVirtualSystem method of the Msvm_VirtualSystemManagementService class. -Windows Server 2008: The AllowFullSCSICommandSet property is not supported.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AllowFullSCSICommandSet { - get { - if ((curObj["AllowFullSCSICommandSet"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AllowFullSCSICommandSet"])); - } - set { - curObj["AllowFullSCSICommandSet"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAllowReducedFcRedundancyNull { - get { - if ((curObj["AllowReducedFcRedundancy"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +Windows Server 2008: The AllowFullSCSICommandSet property is not supported.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AllowFullSCSICommandSet { + get { + if ((curObj["AllowFullSCSICommandSet"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AllowFullSCSICommandSet"])); + } + set { + curObj["AllowFullSCSICommandSet"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAllowReducedFcRedundancyNull { + get { + if ((curObj["AllowReducedFcRedundancy"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"Indicates whether live migration of a virtual machine that is configured with a virtual FC adapter is allowed to a destination machine, without doing any checks for the existence of paths to the storage devices on the destination The default value of this property is FALSE. If set to TRUE, the VM can be live migrated to a target machine which may have no or reduced paths to the target FC devices. The guest operating system may lose connectivity to storage and may behave in an unpredictable manner. - This property should be cleared after a live migration")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool AllowReducedFcRedundancy { - get { - if ((curObj["AllowReducedFcRedundancy"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["AllowReducedFcRedundancy"])); - } - set { - curObj["AllowReducedFcRedundancy"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticRecoveryActionNull { - get { - if ((curObj["AutomaticRecoveryAction"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort AutomaticRecoveryAction { - get { - if ((curObj["AutomaticRecoveryAction"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["AutomaticRecoveryAction"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticShutdownActionNull { - get { - if ((curObj["AutomaticShutdownAction"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort AutomaticShutdownAction { - get { - if ((curObj["AutomaticShutdownAction"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["AutomaticShutdownAction"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticStartupActionNull { - get { - if ((curObj["AutomaticStartupAction"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort AutomaticStartupAction { - get { - if ((curObj["AutomaticStartupAction"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["AutomaticStartupAction"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticStartupActionDelayNull { - get { - if ((curObj["AutomaticStartupActionDelay"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime AutomaticStartupActionDelay { - get { - if ((curObj["AutomaticStartupActionDelay"] != null)) { - return ToDateTime(((string)(curObj["AutomaticStartupActionDelay"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsAutomaticStartupActionSequenceNumberNull { - get { - if ((curObj["AutomaticStartupActionSequenceNumber"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public ushort AutomaticStartupActionSequenceNumber { - get { - if ((curObj["AutomaticStartupActionSequenceNumber"] == null)) { - return System.Convert.ToUInt16(0); - } - return ((ushort)(curObj["AutomaticStartupActionSequenceNumber"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The serial number of the base board for the virtual computer system.\nThis is a re" + - "ad-only property, but it can be changed using the ModifyVirtualSystem method of " + - "the Msvm_VirtualSystemManagementService class.")] - public string BaseBoardSerialNumber { - get { - return ((string)(curObj["BaseBoardSerialNumber"])); - } - set { - curObj["BaseBoardSerialNumber"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The globally-unique identifier for the BIOS of the virtual computer system.\nThis " + - "is a read-only property, but it can be changed using the ModifyVirtualSystem met" + - "hod of the Msvm_VirtualSystemManagementService class.")] - public string BIOSGUID { - get { - return ((string)(curObj["BIOSGUID"])); - } - set { - curObj["BIOSGUID"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsBIOSNumLockNull { - get { - if ((curObj["BIOSNumLock"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + This property should be cleared after a live migration")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool AllowReducedFcRedundancy { + get { + if ((curObj["AllowReducedFcRedundancy"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["AllowReducedFcRedundancy"])); + } + set { + curObj["AllowReducedFcRedundancy"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticRecoveryActionNull { + get { + if ((curObj["AutomaticRecoveryAction"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort AutomaticRecoveryAction { + get { + if ((curObj["AutomaticRecoveryAction"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["AutomaticRecoveryAction"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticShutdownActionNull { + get { + if ((curObj["AutomaticShutdownAction"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort AutomaticShutdownAction { + get { + if ((curObj["AutomaticShutdownAction"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["AutomaticShutdownAction"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticStartupActionNull { + get { + if ((curObj["AutomaticStartupAction"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort AutomaticStartupAction { + get { + if ((curObj["AutomaticStartupAction"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["AutomaticStartupAction"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticStartupActionDelayNull { + get { + if ((curObj["AutomaticStartupActionDelay"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime AutomaticStartupActionDelay { + get { + if ((curObj["AutomaticStartupActionDelay"] != null)) { + return ToDateTime(((string)(curObj["AutomaticStartupActionDelay"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsAutomaticStartupActionSequenceNumberNull { + get { + if ((curObj["AutomaticStartupActionSequenceNumber"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public ushort AutomaticStartupActionSequenceNumber { + get { + if ((curObj["AutomaticStartupActionSequenceNumber"] == null)) { + return System.Convert.ToUInt16(0); + } + return ((ushort)(curObj["AutomaticStartupActionSequenceNumber"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The serial number of the base board for the virtual computer system.\nThis is a re" + + "ad-only property, but it can be changed using the ModifyVirtualSystem method of " + + "the Msvm_VirtualSystemManagementService class.")] + public string BaseBoardSerialNumber { + get { + return ((string)(curObj["BaseBoardSerialNumber"])); + } + set { + curObj["BaseBoardSerialNumber"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The globally-unique identifier for the BIOS of the virtual computer system.\nThis " + + "is a read-only property, but it can be changed using the ModifyVirtualSystem met" + + "hod of the Msvm_VirtualSystemManagementService class.")] + public string BIOSGUID { + get { + return ((string)(curObj["BIOSGUID"])); + } + set { + curObj["BIOSGUID"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsBIOSNumLockNull { + get { + if ((curObj["BIOSNumLock"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"This property is set to TRUE if the num lock key is set to on by the BIOS, FALSE if the num lock key is set to off by the BIOS. -This is a read-only property, but it can be changed using the ModifyVirtualSystem method of the Msvm_VirtualSystemManagementService class.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool BIOSNumLock { - get { - if ((curObj["BIOSNumLock"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["BIOSNumLock"])); - } - set { - curObj["BIOSNumLock"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The serial number of the BIOS for the virtual computer system.\nThis is a read-onl" + - "y property, but it can be changed using the ModifyVirtualSystem method of the Ms" + - "vm_VirtualSystemManagementService class.")] - public string BIOSSerialNumber { - get { - return ((string)(curObj["BIOSSerialNumber"])); - } - set { - curObj["BIOSSerialNumber"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +This is a read-only property, but it can be changed using the ModifyVirtualSystem method of the Msvm_VirtualSystemManagementService class.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool BIOSNumLock { + get { + if ((curObj["BIOSNumLock"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["BIOSNumLock"])); + } + set { + curObj["BIOSNumLock"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The serial number of the BIOS for the virtual computer system.\nThis is a read-onl" + + "y property, but it can be changed using the ModifyVirtualSystem method of the Ms" + + "vm_VirtualSystemManagementService class.")] + public string BIOSSerialNumber { + get { + return ((string)(curObj["BIOSSerialNumber"])); + } + set { + curObj["BIOSSerialNumber"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"The boot order set within the BIOS of the virtual computer system. This property is an array of values, max length 4, where each value indicates a device to boot from. The virtual computer system will first attempt to boot from the device indicated by the first value within the array. If that device does not contain a boot sector, the virtual computer system will attempt to boot from the next device specified by the BootOrder property and so on. If no device specified within the BootOrder contains a boot sector the virtual computer system will fail to boot. The default value for a virtual computer system is [0, 1, 2, 3, 4]. Value definitions: 0 (Floppy): The virtual computer system will attempt to boot from the floppy disk within the floppy drive. @@ -534,1157 +534,1157 @@ public string BIOSSerialNumber { 3 (PXE Boot): The virtual computer system will attempt to PXE boot from the network. 4 (SCSI Hard Drive): The virtual computer system will attempt to boot from the first hard drive found attached to a SCSI controller with a boot sector. 5-65535: Reserved -This is a read-only property, but it can be changed using the ModifyVirtualSystem method of the Msvm_VirtualSystemManagementService class.")] - public ushort[] BootOrder { - get { - return ((ushort[])(curObj["BootOrder"])); - } - set { - curObj["BootOrder"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Caption { - get { - return ((string)(curObj["Caption"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The asset tag of the chassis for the virtual computer system.\nThis is a read-only" + - " property, but it can be changed using the ModifyVirtualSystem method of the Msv" + - "m_VirtualSystemManagementService class.")] - public string ChassisAssetTag { - get { - return ((string)(curObj["ChassisAssetTag"])); - } - set { - curObj["ChassisAssetTag"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The serial number of the chassis for the virtual computer system.\nThis is a read-" + - "only property, but it can be changed using the ModifyVirtualSystem method of the" + - " Msvm_VirtualSystemManagementService class.")] - public string ChassisSerialNumber { - get { - return ((string)(curObj["ChassisSerialNumber"])); - } - set { - curObj["ChassisSerialNumber"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ConfigurationDataRoot { - get { - return ((string)(curObj["ConfigurationDataRoot"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ConfigurationFile { - get { - return ((string)(curObj["ConfigurationFile"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ConfigurationID { - get { - return ((string)(curObj["ConfigurationID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsCreationTimeNull { - get { - if ((curObj["CreationTime"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [TypeConverter(typeof(WMIValueTypeConverter))] - public System.DateTime CreationTime { - get { - if ((curObj["CreationTime"] != null)) { - return ToDateTime(((string)(curObj["CreationTime"]))); - } - else { - return System.DateTime.MinValue; - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDebugChannelIdNull { - get { - if ((curObj["DebugChannelId"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The channel identifier used to debug the virtual system using the VUD unified deb" + - "ugger.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint DebugChannelId { - get { - if ((curObj["DebugChannelId"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["DebugChannelId"])); - } - set { - curObj["DebugChannelId"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDebugPortNull { - get { - if ((curObj["DebugPort"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The tcpip port used to debug the virtual system using synthetic debugging.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public uint DebugPort { - get { - if ((curObj["DebugPort"] == null)) { - return System.Convert.ToUInt32(0); - } - return ((uint)(curObj["DebugPort"])); - } - set { - curObj["DebugPort"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsDebugPortEnabledNull { - get { - if ((curObj["DebugPortEnabled"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Whether the virtual system is using synthetic debugging.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public DebugPortEnabledValues DebugPortEnabled { - get { - if ((curObj["DebugPortEnabled"] == null)) { - return ((DebugPortEnabledValues)(System.Convert.ToInt32(3))); - } - return ((DebugPortEnabledValues)(System.Convert.ToInt32(curObj["DebugPortEnabled"]))); - } - set { - if ((DebugPortEnabledValues.NULL_ENUM_VALUE == value)) { - curObj["DebugPortEnabled"] = null; - } - else { - curObj["DebugPortEnabled"] = value; - } - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string Description { - get { - return ((string)(curObj["Description"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string ElementName { - get { - return ((string)(curObj["ElementName"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsIncrementalBackupEnabledNull { - get { - if ((curObj["IncrementalBackupEnabled"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("Indicates whether the Hyper-V VSS writer supports taking incremental backup of th" + - "is Virtual machine.\nThis is a read-write property.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool IncrementalBackupEnabled { - get { - if ((curObj["IncrementalBackupEnabled"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["IncrementalBackupEnabled"])); - } - set { - curObj["IncrementalBackupEnabled"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string InstanceID { - get { - return ((string)(curObj["InstanceID"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsIsSavedNull { - get { - if ((curObj["IsSaved"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +This is a read-only property, but it can be changed using the ModifyVirtualSystem method of the Msvm_VirtualSystemManagementService class.")] + public ushort[] BootOrder { + get { + return ((ushort[])(curObj["BootOrder"])); + } + set { + curObj["BootOrder"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Caption { + get { + return ((string)(curObj["Caption"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The asset tag of the chassis for the virtual computer system.\nThis is a read-only" + + " property, but it can be changed using the ModifyVirtualSystem method of the Msv" + + "m_VirtualSystemManagementService class.")] + public string ChassisAssetTag { + get { + return ((string)(curObj["ChassisAssetTag"])); + } + set { + curObj["ChassisAssetTag"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The serial number of the chassis for the virtual computer system.\nThis is a read-" + + "only property, but it can be changed using the ModifyVirtualSystem method of the" + + " Msvm_VirtualSystemManagementService class.")] + public string ChassisSerialNumber { + get { + return ((string)(curObj["ChassisSerialNumber"])); + } + set { + curObj["ChassisSerialNumber"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ConfigurationDataRoot { + get { + return ((string)(curObj["ConfigurationDataRoot"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ConfigurationFile { + get { + return ((string)(curObj["ConfigurationFile"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ConfigurationID { + get { + return ((string)(curObj["ConfigurationID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsCreationTimeNull { + get { + if ((curObj["CreationTime"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [TypeConverter(typeof(WMIValueTypeConverter))] + public System.DateTime CreationTime { + get { + if ((curObj["CreationTime"] != null)) { + return ToDateTime(((string)(curObj["CreationTime"]))); + } + else { + return System.DateTime.MinValue; + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDebugChannelIdNull { + get { + if ((curObj["DebugChannelId"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The channel identifier used to debug the virtual system using the VUD unified deb" + + "ugger.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint DebugChannelId { + get { + if ((curObj["DebugChannelId"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["DebugChannelId"])); + } + set { + curObj["DebugChannelId"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDebugPortNull { + get { + if ((curObj["DebugPort"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The tcpip port used to debug the virtual system using synthetic debugging.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public uint DebugPort { + get { + if ((curObj["DebugPort"] == null)) { + return System.Convert.ToUInt32(0); + } + return ((uint)(curObj["DebugPort"])); + } + set { + curObj["DebugPort"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsDebugPortEnabledNull { + get { + if ((curObj["DebugPortEnabled"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Whether the virtual system is using synthetic debugging.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public DebugPortEnabledValues DebugPortEnabled { + get { + if ((curObj["DebugPortEnabled"] == null)) { + return ((DebugPortEnabledValues)(System.Convert.ToInt32(3))); + } + return ((DebugPortEnabledValues)(System.Convert.ToInt32(curObj["DebugPortEnabled"]))); + } + set { + if ((DebugPortEnabledValues.NULL_ENUM_VALUE == value)) { + curObj["DebugPortEnabled"] = null; + } + else { + curObj["DebugPortEnabled"] = value; + } + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string Description { + get { + return ((string)(curObj["Description"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string ElementName { + get { + return ((string)(curObj["ElementName"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsIncrementalBackupEnabledNull { + get { + if ((curObj["IncrementalBackupEnabled"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("Indicates whether the Hyper-V VSS writer supports taking incremental backup of th" + + "is Virtual machine.\nThis is a read-write property.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool IncrementalBackupEnabled { + get { + if ((curObj["IncrementalBackupEnabled"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["IncrementalBackupEnabled"])); + } + set { + curObj["IncrementalBackupEnabled"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string InstanceID { + get { + return ((string)(curObj["InstanceID"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsIsSavedNull { + get { + if ((curObj["IsSaved"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"This property is set to TRUE if the configuration has a reference to a saved state file, FALSE if not. Note that this does not indicate the presence of such a file, only that the configuration specifies one. -This is a read-only property, it cannot be changed.")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool IsSaved { - get { - if ((curObj["IsSaved"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["IsSaved"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string LogDataRoot { - get { - return ((string)(curObj["LogDataRoot"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string[] Notes { - get { - return ((string[])(curObj["Notes"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The object path for the snapshot Msvm_VirtualSystemSettingData from which this ob" + - "ject is based. This property will be NULL if this object is not based off a snap" + - "shot.")] - public string Parent { - get { - return ((string)(curObj["Parent"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string RecoveryFile { - get { - return ((string)(curObj["RecoveryFile"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SnapshotDataRoot { - get { - return ((string)(curObj["SnapshotDataRoot"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SuspendDataRoot { - get { - return ((string)(curObj["SuspendDataRoot"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string SwapFileDataRoot { - get { - return ((string)(curObj["SwapFileDataRoot"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The version of the virtual system in a format of \"major.minor\", for example \"2.0\"" + - ".\nWindows Server 2008: The Version property is not supported.")] - public string Version { - get { - return ((string)(curObj["Version"])); - } - } - - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public bool IsVirtualNumaEnabledNull { - get { - if ((curObj["VirtualNumaEnabled"] == null)) { - return true; - } - else { - return false; - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] +This is a read-only property, it cannot be changed.")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool IsSaved { + get { + if ((curObj["IsSaved"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["IsSaved"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string LogDataRoot { + get { + return ((string)(curObj["LogDataRoot"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string[] Notes { + get { + return ((string[])(curObj["Notes"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The object path for the snapshot Msvm_VirtualSystemSettingData from which this ob" + + "ject is based. This property will be NULL if this object is not based off a snap" + + "shot.")] + public string Parent { + get { + return ((string)(curObj["Parent"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string RecoveryFile { + get { + return ((string)(curObj["RecoveryFile"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SnapshotDataRoot { + get { + return ((string)(curObj["SnapshotDataRoot"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SuspendDataRoot { + get { + return ((string)(curObj["SuspendDataRoot"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string SwapFileDataRoot { + get { + return ((string)(curObj["SwapFileDataRoot"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The version of the virtual system in a format of \"major.minor\", for example \"2.0\"" + + ".\nWindows Server 2008: The Version property is not supported.")] + public string Version { + get { + return ((string)(curObj["Version"])); + } + } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool IsVirtualNumaEnabledNull { + get { + if ((curObj["VirtualNumaEnabled"] == null)) { + return true; + } + else { + return false; + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [Description(@"Indicates whether virtual non-uniform memory access (NUMA) nodes are projected into the virtual machine. If FALSE, the virtual machine will have a single node. If TRUE, the number of virtual NUMA nodes projected into the virtual machine is determined from the values of the Msvm_ProcessorSettingData.MaxProcessorsPerNumaNode and Msvm_MemorySettingData.MaxMemoryBlocksPerNumaNode properties. -")] - [TypeConverter(typeof(WMIValueTypeConverter))] - public bool VirtualNumaEnabled { - get { - if ((curObj["VirtualNumaEnabled"] == null)) { - return System.Convert.ToBoolean(0); - } - return ((bool)(curObj["VirtualNumaEnabled"])); - } - set { - curObj["VirtualNumaEnabled"] = value; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Description("The name of the CIM_ComputerSystem to which this setting data belongs")] - public string VirtualSystemIdentifier { - get { - return ((string)(curObj["VirtualSystemIdentifier"])); - } - } - - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public string VirtualSystemType { - get { - return ((string)(curObj["VirtualSystemType"])); - } - } - - private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { - if (((path != null) - && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); - } - } - - private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { - if (((theObj != null) - && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { - return true; - } - else { - System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); - if ((parentClasses != null)) { - int count = 0; - for (count = 0; (count < parentClasses.Length); count = (count + 1)) { - if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { - return true; - } - } - } - } - return false; - } - - private void ResetAdditionalRecoveryInformation() { - curObj["AdditionalRecoveryInformation"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeAllowFullSCSICommandSet() { - if ((this.IsAllowFullSCSICommandSetNull == false)) { - return true; - } - return false; - } - - private void ResetAllowFullSCSICommandSet() { - curObj["AllowFullSCSICommandSet"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeAllowReducedFcRedundancy() { - if ((this.IsAllowReducedFcRedundancyNull == false)) { - return true; - } - return false; - } - - private void ResetAllowReducedFcRedundancy() { - curObj["AllowReducedFcRedundancy"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeAutomaticRecoveryAction() { - if ((this.IsAutomaticRecoveryActionNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticShutdownAction() { - if ((this.IsAutomaticShutdownActionNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticStartupAction() { - if ((this.IsAutomaticStartupActionNull == false)) { - return true; - } - return false; - } - - // Converts a given datetime in DMTF format to System.DateTime object. - static System.DateTime ToDateTime(string dmtfDate) { - System.DateTime initializer = System.DateTime.MinValue; - int year = initializer.Year; - int month = initializer.Month; - int day = initializer.Day; - int hour = initializer.Hour; - int minute = initializer.Minute; - int second = initializer.Second; - long ticks = 0; - string dmtf = dmtfDate; - System.DateTime datetime = System.DateTime.MinValue; - string tempString = string.Empty; - if ((dmtf == null)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length == 0)) { - throw new System.ArgumentOutOfRangeException(); - } - if ((dmtf.Length != 25)) { - throw new System.ArgumentOutOfRangeException(); - } - try { - tempString = dmtf.Substring(0, 4); - if (("****" != tempString)) { - year = int.Parse(tempString); - } - tempString = dmtf.Substring(4, 2); - if (("**" != tempString)) { - month = int.Parse(tempString); - } - tempString = dmtf.Substring(6, 2); - if (("**" != tempString)) { - day = int.Parse(tempString); - } - tempString = dmtf.Substring(8, 2); - if (("**" != tempString)) { - hour = int.Parse(tempString); - } - tempString = dmtf.Substring(10, 2); - if (("**" != tempString)) { - minute = int.Parse(tempString); - } - tempString = dmtf.Substring(12, 2); - if (("**" != tempString)) { - second = int.Parse(tempString); - } - tempString = dmtf.Substring(15, 6); - if (("******" != tempString)) { - ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); - } - if (((((((((year < 0) - || (month < 0)) - || (day < 0)) - || (hour < 0)) - || (minute < 0)) - || (minute < 0)) - || (second < 0)) - || (ticks < 0))) { - throw new System.ArgumentOutOfRangeException(); - } - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - datetime = new System.DateTime(year, month, day, hour, minute, second, 0); - datetime = datetime.AddTicks(ticks); - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); - int UTCOffset = 0; - int OffsetToBeAdjusted = 0; - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - tempString = dmtf.Substring(22, 3); - if ((tempString != "******")) { - tempString = dmtf.Substring(21, 4); - try { - UTCOffset = int.Parse(tempString); - } - catch (System.Exception e) { - throw new System.ArgumentOutOfRangeException(null, e.Message); - } - OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); - datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); - } - return datetime; - } - - // Converts a given System.DateTime object to DMTF datetime format. - static string ToDmtfDateTime(System.DateTime date) { - string utcString = string.Empty; - System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); - long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); - if ((System.Math.Abs(OffsetMins) > 999)) { - date = date.ToUniversalTime(); - utcString = "+000"; - } - else { - if ((tickOffset.Ticks >= 0)) { - utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); - } - else { - string strTemp = ((long)(OffsetMins)).ToString(); - utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); - } - } - string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, "."); - System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); - long microsec = ((long)((((date.Ticks - dtTemp.Ticks) - * 1000) - / System.TimeSpan.TicksPerMillisecond))); - string strMicrosec = ((long)(microsec)).ToString(); - if ((strMicrosec.Length > 6)) { - strMicrosec = strMicrosec.Substring(0, 6); - } - dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); - dmtfDateTime = string.Concat(dmtfDateTime, utcString); - return dmtfDateTime; - } - - private bool ShouldSerializeAutomaticStartupActionDelay() { - if ((this.IsAutomaticStartupActionDelayNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeAutomaticStartupActionSequenceNumber() { - if ((this.IsAutomaticStartupActionSequenceNumberNull == false)) { - return true; - } - return false; - } - - private void ResetBaseBoardSerialNumber() { - curObj["BaseBoardSerialNumber"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetBIOSGUID() { - curObj["BIOSGUID"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeBIOSNumLock() { - if ((this.IsBIOSNumLockNull == false)) { - return true; - } - return false; - } - - private void ResetBIOSNumLock() { - curObj["BIOSNumLock"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetBIOSSerialNumber() { - curObj["BIOSSerialNumber"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetBootOrder() { - curObj["BootOrder"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetChassisAssetTag() { - curObj["ChassisAssetTag"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private void ResetChassisSerialNumber() { - curObj["ChassisSerialNumber"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeCreationTime() { - if ((this.IsCreationTimeNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeDebugChannelId() { - if ((this.IsDebugChannelIdNull == false)) { - return true; - } - return false; - } - - private void ResetDebugChannelId() { - curObj["DebugChannelId"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeDebugPort() { - if ((this.IsDebugPortNull == false)) { - return true; - } - return false; - } - - private void ResetDebugPort() { - curObj["DebugPort"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeDebugPortEnabled() { - if ((this.IsDebugPortEnabledNull == false)) { - return true; - } - return false; - } - - private void ResetDebugPortEnabled() { - curObj["DebugPortEnabled"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeIncrementalBackupEnabled() { - if ((this.IsIncrementalBackupEnabledNull == false)) { - return true; - } - return false; - } - - private void ResetIncrementalBackupEnabled() { - curObj["IncrementalBackupEnabled"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - private bool ShouldSerializeIsSaved() { - if ((this.IsIsSavedNull == false)) { - return true; - } - return false; - } - - private bool ShouldSerializeVirtualNumaEnabled() { - if ((this.IsVirtualNumaEnabledNull == false)) { - return true; - } - return false; - } - - private void ResetVirtualNumaEnabled() { - curObj["VirtualNumaEnabled"] = null; - if (((isEmbedded == false) - && (AutoCommitProp == true))) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject() { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(); - } - } - - [Browsable(true)] - public void CommitObject(System.Management.PutOptions putOptions) { - if ((isEmbedded == false)) { - PrivateLateBoundObject.Put(putOptions); - } - } - - private void Initialize() { - AutoCommitProp = true; - isEmbedded = false; - } - - private static string ConstructPath(string keyInstanceID) { - string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualSystemSettingData"; - strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); - return strPath; - } - - private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { - Initialize(); - if ((path != null)) { - if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { - throw new System.ArgumentException("Class name does not match."); - } - } - PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); - PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); - curObj = PrivateLateBoundObject; - } - - // Different overloads of GetInstances() help in enumerating instances of the WMI class. - public static VirtualSystemSettingDataCollection GetInstances() { - return GetInstances(null, null, null); - } - - public static VirtualSystemSettingDataCollection GetInstances(string condition) { - return GetInstances(null, condition, null); - } - - public static VirtualSystemSettingDataCollection GetInstances(string[] selectedProperties) { - return GetInstances(null, null, selectedProperties); - } - - public static VirtualSystemSettingDataCollection GetInstances(string condition, string[] selectedProperties) { - return GetInstances(null, condition, selectedProperties); - } - - public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); - pathObj.ClassName = "Msvm_VirtualSystemSettingData"; - pathObj.NamespacePath = "root\\virtualization\\v2"; - System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); - if ((enumOptions == null)) { - enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - } - return new VirtualSystemSettingDataCollection(clsObject.GetInstances(enumOptions)); - } - - public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { - return GetInstances(mgmtScope, condition, null); - } - - public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { - return GetInstances(mgmtScope, null, selectedProperties); - } - - public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { - if ((mgmtScope == null)) { - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; - } - else { - mgmtScope = statMgmtScope; - } - } - System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualSystemSettingData", condition, selectedProperties)); - System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); - enumOptions.EnsureLocatable = true; - ObjectSearcher.Options = enumOptions; - return new VirtualSystemSettingDataCollection(ObjectSearcher.Get()); - } - - [Browsable(true)] - public static VirtualSystemSettingData CreateInstance() { - System.Management.ManagementScope mgmtScope = null; - if ((statMgmtScope == null)) { - mgmtScope = new System.Management.ManagementScope(); - mgmtScope.Path.NamespacePath = CreatedWmiNamespace; - } - else { - mgmtScope = statMgmtScope; - } - System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); - System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); - return new VirtualSystemSettingData(tmpMgmtClass.CreateInstance()); - } - - [Browsable(true)] - public void Delete() { - PrivateLateBoundObject.Delete(); - } - - public enum DebugPortEnabledValues { - - Val__Off = 0, - - On = 1, - - OnAutoAssigned = 2, - - NULL_ENUM_VALUE = 3, - } - - // Enumerator implementation for enumerating instances of the class. - public class VirtualSystemSettingDataCollection : object, ICollection { - - private ManagementObjectCollection privColObj; - - public VirtualSystemSettingDataCollection(ManagementObjectCollection objCollection) { - privColObj = objCollection; - } - - public virtual int Count { - get { - return privColObj.Count; - } - } - - public virtual bool IsSynchronized { - get { - return privColObj.IsSynchronized; - } - } - - public virtual object SyncRoot { - get { - return this; - } - } - - public virtual void CopyTo(System.Array array, int index) { - privColObj.CopyTo(array, index); - int nCtr; - for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { - array.SetValue(new VirtualSystemSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); - } - } - - public virtual System.Collections.IEnumerator GetEnumerator() { - return new VirtualSystemSettingDataEnumerator(privColObj.GetEnumerator()); - } - - public class VirtualSystemSettingDataEnumerator : object, System.Collections.IEnumerator { - - private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; - - public VirtualSystemSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { - privObjEnum = objEnum; - } - - public virtual object Current { - get { - return new VirtualSystemSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); - } - } - - public virtual bool MoveNext() { - return privObjEnum.MoveNext(); - } - - public virtual void Reset() { - privObjEnum.Reset(); - } - } - } - - // TypeConverter to handle null values for ValueType properties - public class WMIValueTypeConverter : TypeConverter { - - private TypeConverter baseConverter; - - private System.Type baseType; - - public WMIValueTypeConverter(System.Type inBaseType) { - baseConverter = TypeDescriptor.GetConverter(inBaseType); - baseType = inBaseType; - } - - public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { - return baseConverter.CanConvertFrom(context, srcType); - } - - public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { - return baseConverter.CanConvertTo(context, destinationType); - } - - public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { - return baseConverter.ConvertFrom(context, culture, value); - } - - public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { - return baseConverter.CreateInstance(context, dictionary); - } - - public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetCreateInstanceSupported(context); - } - - public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { - return baseConverter.GetProperties(context, value, attributeVar); - } - - public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetPropertiesSupported(context); - } - - public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValues(context); - } - - public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesExclusive(context); - } - - public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { - return baseConverter.GetStandardValuesSupported(context); - } - - public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { - if ((baseType.BaseType == typeof(System.Enum))) { - if ((value.GetType() == destinationType)) { - return value; - } - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return "NULL_ENUM_VALUE" ; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((baseType == typeof(bool)) - && (baseType.BaseType == typeof(System.ValueType)))) { - if ((((value == null) - && (context != null)) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - if (((context != null) - && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { - return ""; - } - return baseConverter.ConvertTo(context, culture, value, destinationType); - } - } - - // Embedded class to represent WMI system Properties. - [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] - public class ManagementSystemProperties { - - private System.Management.ManagementBaseObject PrivateLateBoundObject; - - public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { - PrivateLateBoundObject = ManagedObject; - } - - [Browsable(true)] - public int GENUS { - get { - return ((int)(PrivateLateBoundObject["__GENUS"])); - } - } - - [Browsable(true)] - public string CLASS { - get { - return ((string)(PrivateLateBoundObject["__CLASS"])); - } - } - - [Browsable(true)] - public string SUPERCLASS { - get { - return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); - } - } - - [Browsable(true)] - public string DYNASTY { - get { - return ((string)(PrivateLateBoundObject["__DYNASTY"])); - } - } - - [Browsable(true)] - public string RELPATH { - get { - return ((string)(PrivateLateBoundObject["__RELPATH"])); - } - } - - [Browsable(true)] - public int PROPERTY_COUNT { - get { - return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); - } - } - - [Browsable(true)] - public string[] DERIVATION { - get { - return ((string[])(PrivateLateBoundObject["__DERIVATION"])); - } - } - - [Browsable(true)] - public string SERVER { - get { - return ((string)(PrivateLateBoundObject["__SERVER"])); - } - } - - [Browsable(true)] - public string NAMESPACE { - get { - return ((string)(PrivateLateBoundObject["__NAMESPACE"])); - } - } - - [Browsable(true)] - public string PATH { - get { - return ((string)(PrivateLateBoundObject["__PATH"])); - } - } - } - } -} +")] + [TypeConverter(typeof(WMIValueTypeConverter))] + public bool VirtualNumaEnabled { + get { + if ((curObj["VirtualNumaEnabled"] == null)) { + return System.Convert.ToBoolean(0); + } + return ((bool)(curObj["VirtualNumaEnabled"])); + } + set { + curObj["VirtualNumaEnabled"] = value; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Description("The name of the CIM_ComputerSystem to which this setting data belongs")] + public string VirtualSystemIdentifier { + get { + return ((string)(curObj["VirtualSystemIdentifier"])); + } + } + + [Browsable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public string VirtualSystemType { + get { + return ((string)(curObj["VirtualSystemType"])); + } + } + + private bool CheckIfProperClass(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions OptionsParam) { + if (((path != null) + && (string.Compare(path.ClassName, this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + return CheckIfProperClass(new System.Management.ManagementObject(mgmtScope, path, OptionsParam)); + } + } + + private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj) { + if (((theObj != null) + && (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))) { + return true; + } + else { + System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"])); + if ((parentClasses != null)) { + int count = 0; + for (count = 0; (count < parentClasses.Length); count = (count + 1)) { + if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)) { + return true; + } + } + } + } + return false; + } + + private void ResetAdditionalRecoveryInformation() { + curObj["AdditionalRecoveryInformation"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeAllowFullSCSICommandSet() { + if ((this.IsAllowFullSCSICommandSetNull == false)) { + return true; + } + return false; + } + + private void ResetAllowFullSCSICommandSet() { + curObj["AllowFullSCSICommandSet"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeAllowReducedFcRedundancy() { + if ((this.IsAllowReducedFcRedundancyNull == false)) { + return true; + } + return false; + } + + private void ResetAllowReducedFcRedundancy() { + curObj["AllowReducedFcRedundancy"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeAutomaticRecoveryAction() { + if ((this.IsAutomaticRecoveryActionNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticShutdownAction() { + if ((this.IsAutomaticShutdownActionNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticStartupAction() { + if ((this.IsAutomaticStartupActionNull == false)) { + return true; + } + return false; + } + + // Converts a given datetime in DMTF format to System.DateTime object. + static System.DateTime ToDateTime(string dmtfDate) { + System.DateTime initializer = System.DateTime.MinValue; + int year = initializer.Year; + int month = initializer.Month; + int day = initializer.Day; + int hour = initializer.Hour; + int minute = initializer.Minute; + int second = initializer.Second; + long ticks = 0; + string dmtf = dmtfDate; + System.DateTime datetime = System.DateTime.MinValue; + string tempString = string.Empty; + if ((dmtf == null)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length == 0)) { + throw new System.ArgumentOutOfRangeException(); + } + if ((dmtf.Length != 25)) { + throw new System.ArgumentOutOfRangeException(); + } + try { + tempString = dmtf.Substring(0, 4); + if (("****" != tempString)) { + year = int.Parse(tempString); + } + tempString = dmtf.Substring(4, 2); + if (("**" != tempString)) { + month = int.Parse(tempString); + } + tempString = dmtf.Substring(6, 2); + if (("**" != tempString)) { + day = int.Parse(tempString); + } + tempString = dmtf.Substring(8, 2); + if (("**" != tempString)) { + hour = int.Parse(tempString); + } + tempString = dmtf.Substring(10, 2); + if (("**" != tempString)) { + minute = int.Parse(tempString); + } + tempString = dmtf.Substring(12, 2); + if (("**" != tempString)) { + second = int.Parse(tempString); + } + tempString = dmtf.Substring(15, 6); + if (("******" != tempString)) { + ticks = (long.Parse(tempString) * ((long)((System.TimeSpan.TicksPerMillisecond / 1000)))); + } + if (((((((((year < 0) + || (month < 0)) + || (day < 0)) + || (hour < 0)) + || (minute < 0)) + || (minute < 0)) + || (second < 0)) + || (ticks < 0))) { + throw new System.ArgumentOutOfRangeException(); + } + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + datetime = new System.DateTime(year, month, day, hour, minute, second, 0); + datetime = datetime.AddTicks(ticks); + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(datetime); + int UTCOffset = 0; + int OffsetToBeAdjusted = 0; + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + tempString = dmtf.Substring(22, 3); + if ((tempString != "******")) { + tempString = dmtf.Substring(21, 4); + try { + UTCOffset = int.Parse(tempString); + } + catch (System.Exception e) { + throw new System.ArgumentOutOfRangeException(null, e.Message); + } + OffsetToBeAdjusted = ((int)((OffsetMins - UTCOffset))); + datetime = datetime.AddMinutes(((double)(OffsetToBeAdjusted))); + } + return datetime; + } + + // Converts a given System.DateTime object to DMTF datetime format. + static string ToDmtfDateTime(System.DateTime date) { + string utcString = string.Empty; + System.TimeSpan tickOffset = System.TimeZone.CurrentTimeZone.GetUtcOffset(date); + long OffsetMins = ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))); + if ((System.Math.Abs(OffsetMins) > 999)) { + date = date.ToUniversalTime(); + utcString = "+000"; + } + else { + if ((tickOffset.Ticks >= 0)) { + utcString = string.Concat("+", ((long)((tickOffset.Ticks / System.TimeSpan.TicksPerMinute))).ToString().PadLeft(3, '0')); + } + else { + string strTemp = ((long)(OffsetMins)).ToString(); + utcString = string.Concat("-", strTemp.Substring(1, (strTemp.Length - 1)).PadLeft(3, '0')); + } + } + string dmtfDateTime = ((int)(date.Year)).ToString().PadLeft(4, '0'); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Month)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Day)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Hour)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Minute)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, ((int)(date.Second)).ToString().PadLeft(2, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, "."); + System.DateTime dtTemp = new System.DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, 0); + long microsec = ((long)((((date.Ticks - dtTemp.Ticks) + * 1000) + / System.TimeSpan.TicksPerMillisecond))); + string strMicrosec = ((long)(microsec)).ToString(); + if ((strMicrosec.Length > 6)) { + strMicrosec = strMicrosec.Substring(0, 6); + } + dmtfDateTime = string.Concat(dmtfDateTime, strMicrosec.PadLeft(6, '0')); + dmtfDateTime = string.Concat(dmtfDateTime, utcString); + return dmtfDateTime; + } + + private bool ShouldSerializeAutomaticStartupActionDelay() { + if ((this.IsAutomaticStartupActionDelayNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeAutomaticStartupActionSequenceNumber() { + if ((this.IsAutomaticStartupActionSequenceNumberNull == false)) { + return true; + } + return false; + } + + private void ResetBaseBoardSerialNumber() { + curObj["BaseBoardSerialNumber"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetBIOSGUID() { + curObj["BIOSGUID"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeBIOSNumLock() { + if ((this.IsBIOSNumLockNull == false)) { + return true; + } + return false; + } + + private void ResetBIOSNumLock() { + curObj["BIOSNumLock"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetBIOSSerialNumber() { + curObj["BIOSSerialNumber"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetBootOrder() { + curObj["BootOrder"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetChassisAssetTag() { + curObj["ChassisAssetTag"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private void ResetChassisSerialNumber() { + curObj["ChassisSerialNumber"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeCreationTime() { + if ((this.IsCreationTimeNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeDebugChannelId() { + if ((this.IsDebugChannelIdNull == false)) { + return true; + } + return false; + } + + private void ResetDebugChannelId() { + curObj["DebugChannelId"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeDebugPort() { + if ((this.IsDebugPortNull == false)) { + return true; + } + return false; + } + + private void ResetDebugPort() { + curObj["DebugPort"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeDebugPortEnabled() { + if ((this.IsDebugPortEnabledNull == false)) { + return true; + } + return false; + } + + private void ResetDebugPortEnabled() { + curObj["DebugPortEnabled"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeIncrementalBackupEnabled() { + if ((this.IsIncrementalBackupEnabledNull == false)) { + return true; + } + return false; + } + + private void ResetIncrementalBackupEnabled() { + curObj["IncrementalBackupEnabled"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + private bool ShouldSerializeIsSaved() { + if ((this.IsIsSavedNull == false)) { + return true; + } + return false; + } + + private bool ShouldSerializeVirtualNumaEnabled() { + if ((this.IsVirtualNumaEnabledNull == false)) { + return true; + } + return false; + } + + private void ResetVirtualNumaEnabled() { + curObj["VirtualNumaEnabled"] = null; + if (((isEmbedded == false) + && (AutoCommitProp == true))) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject() { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(); + } + } + + [Browsable(true)] + public void CommitObject(System.Management.PutOptions putOptions) { + if ((isEmbedded == false)) { + PrivateLateBoundObject.Put(putOptions); + } + } + + private void Initialize() { + AutoCommitProp = true; + isEmbedded = false; + } + + private static string ConstructPath(string keyInstanceID) { + string strPath = "ROOT\\virtualization\\v2:Msvm_VirtualSystemSettingData"; + strPath = string.Concat(strPath, string.Concat(".InstanceID=", string.Concat("\"", string.Concat(keyInstanceID, "\"")))); + return strPath; + } + + private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) { + Initialize(); + if ((path != null)) { + if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) { + throw new System.ArgumentException("Class name does not match."); + } + } + PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions); + PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject); + curObj = PrivateLateBoundObject; + } + + // Different overloads of GetInstances() help in enumerating instances of the WMI class. + public static VirtualSystemSettingDataCollection GetInstances() { + return GetInstances(null, null, null); + } + + public static VirtualSystemSettingDataCollection GetInstances(string condition) { + return GetInstances(null, condition, null); + } + + public static VirtualSystemSettingDataCollection GetInstances(string[] selectedProperties) { + return GetInstances(null, null, selectedProperties); + } + + public static VirtualSystemSettingDataCollection GetInstances(string condition, string[] selectedProperties) { + return GetInstances(null, condition, selectedProperties); + } + + public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, System.Management.EnumerationOptions enumOptions) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementPath pathObj = new System.Management.ManagementPath(); + pathObj.ClassName = "Msvm_VirtualSystemSettingData"; + pathObj.NamespacePath = "root\\virtualization\\v2"; + System.Management.ManagementClass clsObject = new System.Management.ManagementClass(mgmtScope, pathObj, null); + if ((enumOptions == null)) { + enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + } + return new VirtualSystemSettingDataCollection(clsObject.GetInstances(enumOptions)); + } + + public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition) { + return GetInstances(mgmtScope, condition, null); + } + + public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string[] selectedProperties) { + return GetInstances(mgmtScope, null, selectedProperties); + } + + public static VirtualSystemSettingDataCollection GetInstances(System.Management.ManagementScope mgmtScope, string condition, string[] selectedProperties) { + if ((mgmtScope == null)) { + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = "root\\virtualization\\v2"; + } + else { + mgmtScope = statMgmtScope; + } + } + System.Management.ManagementObjectSearcher ObjectSearcher = new System.Management.ManagementObjectSearcher(mgmtScope, new SelectQuery("Msvm_VirtualSystemSettingData", condition, selectedProperties)); + System.Management.EnumerationOptions enumOptions = new System.Management.EnumerationOptions(); + enumOptions.EnsureLocatable = true; + ObjectSearcher.Options = enumOptions; + return new VirtualSystemSettingDataCollection(ObjectSearcher.Get()); + } + + [Browsable(true)] + public static VirtualSystemSettingData CreateInstance() { + System.Management.ManagementScope mgmtScope = null; + if ((statMgmtScope == null)) { + mgmtScope = new System.Management.ManagementScope(); + mgmtScope.Path.NamespacePath = CreatedWmiNamespace; + } + else { + mgmtScope = statMgmtScope; + } + System.Management.ManagementPath mgmtPath = new System.Management.ManagementPath(CreatedClassName); + System.Management.ManagementClass tmpMgmtClass = new System.Management.ManagementClass(mgmtScope, mgmtPath, null); + return new VirtualSystemSettingData(tmpMgmtClass.CreateInstance()); + } + + [Browsable(true)] + public void Delete() { + PrivateLateBoundObject.Delete(); + } + + public enum DebugPortEnabledValues { + + Val__Off = 0, + + On = 1, + + OnAutoAssigned = 2, + + NULL_ENUM_VALUE = 3, + } + + // Enumerator implementation for enumerating instances of the class. + public class VirtualSystemSettingDataCollection : object, ICollection { + + private ManagementObjectCollection privColObj; + + public VirtualSystemSettingDataCollection(ManagementObjectCollection objCollection) { + privColObj = objCollection; + } + + public virtual int Count { + get { + return privColObj.Count; + } + } + + public virtual bool IsSynchronized { + get { + return privColObj.IsSynchronized; + } + } + + public virtual object SyncRoot { + get { + return this; + } + } + + public virtual void CopyTo(System.Array array, int index) { + privColObj.CopyTo(array, index); + int nCtr; + for (nCtr = 0; (nCtr < array.Length); nCtr = (nCtr + 1)) { + array.SetValue(new VirtualSystemSettingData(((System.Management.ManagementObject)(array.GetValue(nCtr)))), nCtr); + } + } + + public virtual System.Collections.IEnumerator GetEnumerator() { + return new VirtualSystemSettingDataEnumerator(privColObj.GetEnumerator()); + } + + public class VirtualSystemSettingDataEnumerator : object, System.Collections.IEnumerator { + + private ManagementObjectCollection.ManagementObjectEnumerator privObjEnum; + + public VirtualSystemSettingDataEnumerator(ManagementObjectCollection.ManagementObjectEnumerator objEnum) { + privObjEnum = objEnum; + } + + public virtual object Current { + get { + return new VirtualSystemSettingData(((System.Management.ManagementObject)(privObjEnum.Current))); + } + } + + public virtual bool MoveNext() { + return privObjEnum.MoveNext(); + } + + public virtual void Reset() { + privObjEnum.Reset(); + } + } + } + + // TypeConverter to handle null values for ValueType properties + public class WMIValueTypeConverter : TypeConverter { + + private TypeConverter baseConverter; + + private System.Type baseType; + + public WMIValueTypeConverter(System.Type inBaseType) { + baseConverter = TypeDescriptor.GetConverter(inBaseType); + baseType = inBaseType; + } + + public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type srcType) { + return baseConverter.CanConvertFrom(context, srcType); + } + + public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Type destinationType) { + return baseConverter.CanConvertTo(context, destinationType); + } + + public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { + return baseConverter.ConvertFrom(context, culture, value); + } + + public override object CreateInstance(System.ComponentModel.ITypeDescriptorContext context, System.Collections.IDictionary dictionary) { + return baseConverter.CreateInstance(context, dictionary); + } + + public override bool GetCreateInstanceSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetCreateInstanceSupported(context); + } + + public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, System.Attribute[] attributeVar) { + return baseConverter.GetProperties(context, value, attributeVar); + } + + public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetPropertiesSupported(context); + } + + public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValues(context); + } + + public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesExclusive(context); + } + + public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) { + return baseConverter.GetStandardValuesSupported(context); + } + + public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType) { + if ((baseType.BaseType == typeof(System.Enum))) { + if ((value.GetType() == destinationType)) { + return value; + } + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return "NULL_ENUM_VALUE" ; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((baseType == typeof(bool)) + && (baseType.BaseType == typeof(System.ValueType)))) { + if ((((value == null) + && (context != null)) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + if (((context != null) + && (context.PropertyDescriptor.ShouldSerializeValue(context.Instance) == false))) { + return ""; + } + return baseConverter.ConvertTo(context, culture, value, destinationType); + } + } + + // Embedded class to represent WMI system Properties. + [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))] + public class ManagementSystemProperties { + + private System.Management.ManagementBaseObject PrivateLateBoundObject; + + public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject) { + PrivateLateBoundObject = ManagedObject; + } + + [Browsable(true)] + public int GENUS { + get { + return ((int)(PrivateLateBoundObject["__GENUS"])); + } + } + + [Browsable(true)] + public string CLASS { + get { + return ((string)(PrivateLateBoundObject["__CLASS"])); + } + } + + [Browsable(true)] + public string SUPERCLASS { + get { + return ((string)(PrivateLateBoundObject["__SUPERCLASS"])); + } + } + + [Browsable(true)] + public string DYNASTY { + get { + return ((string)(PrivateLateBoundObject["__DYNASTY"])); + } + } + + [Browsable(true)] + public string RELPATH { + get { + return ((string)(PrivateLateBoundObject["__RELPATH"])); + } + } + + [Browsable(true)] + public int PROPERTY_COUNT { + get { + return ((int)(PrivateLateBoundObject["__PROPERTY_COUNT"])); + } + } + + [Browsable(true)] + public string[] DERIVATION { + get { + return ((string[])(PrivateLateBoundObject["__DERIVATION"])); + } + } + + [Browsable(true)] + public string SERVER { + get { + return ((string)(PrivateLateBoundObject["__SERVER"])); + } + } + + [Browsable(true)] + public string NAMESPACE { + get { + return ((string)(PrivateLateBoundObject["__NAMESPACE"])); + } + } + + [Browsable(true)] + public string PATH { + get { + return ((string)(PrivateLateBoundObject["__PATH"])); + } + } + } + } +} diff --git a/server/src/test/resources/createNetworkOffering.xml b/server/src/test/resources/createNetworkOffering.xml index 81359cdc72f0..023f0cb89673 100644 --- a/server/src/test/resources/createNetworkOffering.xml +++ b/server/src/test/resources/createNetworkOffering.xml @@ -1,83 +1,83 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +