public virtual void Save() { if (this.Batch) { this._Dirty = true; } else { try { this.Lock.AcquireWriterLock(-1); if (this._deleted || this._shutdown) { return; } PropertyItem[] array = CUtils.CollectionToArray <PropertyItem>((ICollection <PropertyItem>) this.Data.Values); try { this._serializerFile.Save(array); } catch (ThreadAbortException ex) { this._serializerFile.Save(array); } this._Dirty = false; } finally { this.Lock.ReleaseWriterLock(); } } }
public static ServerNicInfo[] GetNetworkAdapterList(ManagementScope scope) { Dictionary <string, ServerNicInfo> dictionary = new Dictionary <string, ServerNicInfo>((IEqualityComparer <string>)StringComparer.CurrentCultureIgnoreCase); ObjectQuery query = new ObjectQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = TRUE"); using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query)) { using (managementObjectSearcher.Get()) { foreach (ManagementObject managementObject in managementObjectSearcher.Get()) { ServerNicInfo serverNicInfo = new ServerNicInfo(); serverNicInfo.IPAddresses = (string[])managementObject["IPAddress"]; serverNicInfo.IPMasks = (string[])managementObject["IPSubnet"]; serverNicInfo.IPGateways = managementObject["DefaultIPGateway"] != null ? (string[])managementObject["DefaultIPGateway"] : (string[])null; serverNicInfo.DNSAddrs = managementObject["DNSServerSearchOrder"] != null ? (string[])managementObject["DNSServerSearchOrder"] : (string[])null; serverNicInfo.DNSDomain = (string)managementObject.Properties["DNSDomain"].Value; serverNicInfo.TcpIpServiceUuid = (string)managementObject["SettingID"]; serverNicInfo.Index = (int)(uint)managementObject["Index"]; serverNicInfo.PNPInstanceId = WMIUtils.GetPNPInstanceId(scope, serverNicInfo.Index); serverNicInfo.DHCPEnabled = (bool)managementObject["DHCPEnabled"]; ManagementObject firstElement = WMIUtils.GetFirstElement(managementObject.GetRelated("Win32_NetworkAdapter")); serverNicInfo.FriendlyName = (string)firstElement["NetConnectionID"]; if (!string.IsNullOrEmpty(serverNicInfo.PNPInstanceId) && !dictionary.ContainsKey(serverNicInfo.TcpIpServiceUuid)) { dictionary.Add(serverNicInfo.TcpIpServiceUuid, serverNicInfo); } } } } return(CUtils.CollectionToArray <ServerNicInfo>((ICollection <ServerNicInfo>)dictionary.Values)); }