private void SetupNetworkInfoTab( ) { AddDataPageToTabControl("Network Info", tcMain, new DataPageControl <DprNetworkInfo>(this) { QueryDataCb = DprNetworkInfo.Generate, SetupColumnsCb = delegate(DataGridView dgv) { DgvHelpers.GenerateAllColumns(dgv, typeof(DprNetworkInfo), new List <string> { @"DefaultIpGateway", @"DnsDomainSuffixSearchOrder", @"DnsServerSearchOrder", @"IpAddress", @"ConnectionStatus" }); MoveStatusColumnsFirst(dgv); DgvHelpers.ConvertToMultilineColumn(DgvHelpers.GetColumn(dgv, @"DefaultIpGateways")); DgvHelpers.ConvertToMultilineColumn(DgvHelpers.GetColumn(dgv, @"DnsDomainSuffixSearchOrders")); DgvHelpers.ConvertToMultilineColumn(DgvHelpers.GetColumn(dgv, @"DnsServerSearchOrders")); DgvHelpers.ConvertToMultilineColumn(DgvHelpers.GetColumn(dgv, @"IpAddresses")); DgvHelpers.ConvertToMultilineColumn(DgvHelpers.GetColumn(dgv, @"WinsServers")); DgvHelpers.MoveColumnToIndex(DgvHelpers.GetColumn(dgv, @"Description"), 2); DgvHelpers.SetColumnHeader(DgvHelpers.GetColumn(dgv, @"ConnectionStatusString"), @"Connection Status"); DgvHelpers.SetVisible(DgvHelpers.GetColumn(dgv, @"InterfaceIndex"), false); DgvHelpers.SetVisible(DgvHelpers.GetColumn(dgv, @"SettingId"), false); foreach (var actionName in DprNetworkInfo.SetupActions( ).Keys) { DgvHelpers.AddButtonColumn(dgv, actionName); } } }); }
public static void Generate(string computerName, SyncList <DprNetworkInfo> result) { Helpers.AssertNotNull(result, @"result SyncList cannot be null"); Helpers.AssertString(computerName, @"Computer name cannot be empty"); var networkInfoList = new List <DprNetworkInfo>( ); try { WmiHelpers.ForEach(computerName, @"SELECT * FROM Win32_NetworkAdapterConfiguration", obj => { var ci = new DprNetworkInfo(computerName); ci.DefaultIpGateway = WmiHelpers.GetStringArray(obj, @"DefaultIPGateway"); ci.Description = WmiHelpers.GetString(obj, @"Description"); ci.DhcpEnabled = WmiHelpers.GetBoolean(obj, @"DHCPEnabled"); ci.DhcpLeaseExpires = WmiHelpers.GetNullableDate(obj, @"DHCPLeaseExpires", true); ci.DhcpLeaseObtained = WmiHelpers.GetNullableDate(obj, @"DHCPLeaseObtained", true); ci.DhcpServer = WmiHelpers.GetString(obj, @"DHCPServer"); ci.DnsDomain = WmiHelpers.GetString(obj, @"DNSDomain"); ci.DnsDomainSuffixSearchOrder = WmiHelpers.GetStringArray(obj, @"DNSDomainSuffixSearchOrder"); ci.DnsEnabledForWinsResolution = WmiHelpers.GetNullableBoolean(obj, @"DNSEnabledForWINSResolution"); ci.DnsHostName = WmiHelpers.GetString(obj, @"DNSHostName"); ci.DnsServerSearchOrder = WmiHelpers.GetStringArray(obj, @"DNSServerSearchOrder"); ci.DomainDnsRegistrationEnabled = WmiHelpers.GetNullableBoolean(obj, @"DomainDNSRegistrationEnabled"); ci.FullDnsRegistrationEnabled = WmiHelpers.GetNullableBoolean(obj, @"FullDNSRegistrationEnabled"); ci.Index = WmiHelpers.GetUInt(obj, @"Index"); ci.InterfaceIndex = WmiHelpers.GetUInt(obj, @"InterfaceIndex"); ci.IpAddress = WmiHelpers.GetStringArray(obj, @"IPAddress"); ci.IpConnectionMetric = WmiHelpers.GetNullableUInt(obj, @"IPConnectionMetric"); ci.IpEnabled = WmiHelpers.GetNullableBoolean(obj, @"IPEnabled"); ci.MacAddress = WmiHelpers.GetString(obj, @"MACAddress"); ci.SettingId = WmiHelpers.GetString(obj, @"SettingID"); ci.WinsEnableLmHostsLookup = WmiHelpers.GetNullableBoolean(obj, @"WINSEnableLMHostsLookup"); ci.WinsHostLookupFile = WmiHelpers.GetString(obj, @"WINSHostLookupFile"); ci.WinsPrimaryServer = WmiHelpers.GetString(obj, @"WINSPrimaryServer"); ci.WinsSecondaryServer = WmiHelpers.GetString(obj, @"WINSSecondaryServer"); ci.WinsScopeId = WmiHelpers.GetString(obj, @"WINSScopeID"); networkInfoList.Add(ci); return(true); }, true, false); } catch (UnauthorizedAccessException) { result.Add(new DprNetworkInfo(computerName, ConnectionStatuses.AuthorizationError)); return; } catch (Exception) { result.Add(new DprNetworkInfo(computerName, ConnectionStatuses.Error)); return; } result.AddRange(networkInfoList); ValidateUniqueness(result); }
public static void Generate( string computerName, SyncList<DprNetworkInfo> result ) { Helpers.AssertNotNull( result, @"result SyncList cannot be null" ); Helpers.AssertString( computerName, @"Computer name cannot be empty" ); var networkInfoList = new List<DprNetworkInfo>( ); try { WmiHelpers.ForEach( computerName, @"SELECT * FROM Win32_NetworkAdapterConfiguration", obj => { var ci = new DprNetworkInfo( computerName ); ci.DefaultIpGateway = WmiHelpers.GetStringArray( obj, @"DefaultIPGateway" ); ci.Description = WmiHelpers.GetString( obj, @"Description" ); ci.DhcpEnabled = WmiHelpers.GetBoolean( obj, @"DHCPEnabled" ); ci.DhcpLeaseExpires = WmiHelpers.GetNullableDate( obj, @"DHCPLeaseExpires", true ); ci.DhcpLeaseObtained = WmiHelpers.GetNullableDate( obj, @"DHCPLeaseObtained", true ); ci.DhcpServer = WmiHelpers.GetString( obj, @"DHCPServer" ); ci.DnsDomain = WmiHelpers.GetString( obj, @"DNSDomain" ); ci.DnsDomainSuffixSearchOrder = WmiHelpers.GetStringArray( obj, @"DNSDomainSuffixSearchOrder" ); ci.DnsEnabledForWinsResolution = WmiHelpers.GetNullableBoolean( obj, @"DNSEnabledForWINSResolution" ); ci.DnsHostName = WmiHelpers.GetString( obj, @"DNSHostName" ); ci.DnsServerSearchOrder = WmiHelpers.GetStringArray( obj, @"DNSServerSearchOrder" ); ci.DomainDnsRegistrationEnabled = WmiHelpers.GetNullableBoolean( obj, @"DomainDNSRegistrationEnabled" ); ci.FullDnsRegistrationEnabled = WmiHelpers.GetNullableBoolean( obj, @"FullDNSRegistrationEnabled" ); ci.Index = WmiHelpers.GetUInt( obj, @"Index" ); ci.InterfaceIndex = WmiHelpers.GetUInt( obj, @"InterfaceIndex" ); ci.IpAddress = WmiHelpers.GetStringArray( obj, @"IPAddress" ); ci.IpConnectionMetric = WmiHelpers.GetNullableUInt( obj, @"IPConnectionMetric" ); ci.IpEnabled = WmiHelpers.GetNullableBoolean( obj, @"IPEnabled" ); ci.MacAddress = WmiHelpers.GetString( obj, @"MACAddress" ); ci.SettingId = WmiHelpers.GetString( obj, @"SettingID" ); ci.WinsEnableLmHostsLookup = WmiHelpers.GetNullableBoolean( obj, @"WINSEnableLMHostsLookup" ); ci.WinsHostLookupFile = WmiHelpers.GetString( obj, @"WINSHostLookupFile" ); ci.WinsPrimaryServer = WmiHelpers.GetString( obj, @"WINSPrimaryServer" ); ci.WinsSecondaryServer = WmiHelpers.GetString( obj, @"WINSSecondaryServer" ); ci.WinsScopeId = WmiHelpers.GetString( obj, @"WINSScopeID" ); networkInfoList.Add( ci ); return true; }, true, false ); } catch( UnauthorizedAccessException ) { result.Add( new DprNetworkInfo( computerName, ConnectionStatuses.AuthorizationError ) ); return; } catch( Exception ) { result.Add( new DprNetworkInfo( computerName, ConnectionStatuses.Error ) ); return; } result.AddRange( networkInfoList ); ValidateUniqueness( result ); }