public SyntheticEthernetPortSettingData GetSyntheticEthernetPortSettings(EthernetSwitchPort port) { // An ASSOCIATOR object provides the cross reference from the EthernetSwitchPort and the // SyntheticEthernetPortSettingData, but generated wrappers do not expose a ASSOCIATOR OF query as a method. // Instead, we use the System.Management to code the equivalant of // string query = string.Format( "ASSOCIATORS OF {{{0}}} WHERE ResultClass = {1}", vm.path, resultclassName); // var wmiObjQuery = new RelatedObjectQuery(port.Path.Path, SyntheticEthernetPortSettingData.CreatedClassName); // NB: default scope of ManagementObjectSearcher is '\\.\root\cimv2', which does not contain // the virtualisation objects. var wmiObjectSearch = new ManagementObjectSearcher(port.Scope, wmiObjQuery); var wmiObjCollection = new SyntheticEthernetPortSettingData.SyntheticEthernetPortSettingDataCollection(wmiObjectSearch.Get()); // When snapshots are taken into account, there can be multiple settings objects // take the first one that isn't a snapshot foreach (SyntheticEthernetPortSettingData wmiObj in wmiObjCollection) { return wmiObj; } var errMsg = string.Format("No SyntheticEthernetPortSettingData for port {0}, path {1}", port.ElementName, port.Path.Path); var ex = new WmiException(errMsg); logger.Error(errMsg, ex); throw ex; }
public SyntheticEthernetPortSettingData[] GetEthernetPortSettings(ComputerSystem vm) { // An ASSOCIATOR object provides the cross reference from the ComputerSettings and the // SyntheticEthernetPortSettingData, via the VirtualSystemSettingData. // However, generated wrappers do not expose a ASSOCIATOR OF query as a method. // Instead, we use the System.Management to code the equivalant of // // string query = string.Format( "ASSOCIATORS OF {{{0}}} WHERE ResultClass = {1}", vm.path, resultclassName); // VirtualSystemSettingData vmSettings = GetVmSettings(vm); var wmiObjQuery = new RelatedObjectQuery(vmSettings.Path.Path, SyntheticEthernetPortSettingData.CreatedClassName); // NB: default scope of ManagementObjectSearcher is '\\.\root\cimv2', which does not contain // the virtualisation objects. var wmiObjectSearch = new ManagementObjectSearcher(vm.Scope, wmiObjQuery); var wmiObjCollection = new SyntheticEthernetPortSettingData.SyntheticEthernetPortSettingDataCollection(wmiObjectSearch.Get()); List<SyntheticEthernetPortSettingData> results = new List<SyntheticEthernetPortSettingData>(wmiObjCollection.Count); foreach (SyntheticEthernetPortSettingData item in wmiObjCollection) { results.Add(item); } return results.ToArray(); }