/// <summary> /// TODO: this method needs some work /// </summary> /// <param name="inputDataItems"></param> /// <returns></returns> protected override PropertyBagDataItem[] GetOutputData(DataItemBase[] inputDataItems) { var result = new List <PropertyBagDataItem>(); var bagItem = new Dictionary <string, object>(); string ipAddressesText = string.Empty; if (_customDnsServers.Count == 0) { try { var ipAddresses = Dns.GetHostAddresses(_testUri.DnsSafeHost); foreach (var ipAddress in ipAddresses) { ipAddressesText += $"{ipAddress}; "; } bagItem.Add("State", "OK"); bagItem.Add("DNSServers", "<System Defined>"); bagItem.Add("Error", ""); bagItem.Add("IP", ipAddressesText); } // catch only name resolution process related exceptions to alert on resolution problem catch (SocketException se) { bagItem.Add("State", "ERROR"); bagItem.Add("DNSServers", "<System Defined>"); bagItem.Add("Error", se.Message); bagItem.Add("IP", ""); } catch (ArgumentException se) { bagItem.Add("State", "ERROR"); bagItem.Add("DNSServers", "<System Defined>"); bagItem.Add("Error", se.Message); bagItem.Add("IP", ""); } } else { int successCount = 0; string errorList = string.Empty; string failedDnsServers = string.Empty, successDnsServers = string.Empty; foreach (var dns in _customDnsServers) { try { var draftIP = TcpHelper.GetHostEntry(_testUri.DnsSafeHost, dns, timeOut: _dnsRequestTimeout); if (draftIP?.AddressList?.Length > 0) { successCount++; foreach (var ipAddress in draftIP.AddressList) { ipAddressesText += $"{ipAddress}; "; } successDnsServers += $"{dns}; "; } else { errorList += $"DNS Server [{dns}] returned no addresses for '{_testUri.DnsSafeHost}'. "; failedDnsServers += $"{dns}; "; } } catch (SocketException e) { errorList += $"Error: [{e.Message}]; "; failedDnsServers += $"{dns}; "; } } string dnsServers = $"Query Success: {successDnsServers} Query empty of failed: {failedDnsServers}"; if (successCount == 0) { bagItem.Add("State", "ERROR"); bagItem.Add("DNSServers", dnsServers); bagItem.Add("Error", errorList); bagItem.Add("IP", ""); } else if (successCount < _minValidResponses) { bagItem.Add("State", "WARNING"); bagItem.Add("DNSServers", dnsServers); bagItem.Add("Error", errorList); bagItem.Add("IP", ipAddressesText); } else { bagItem.Add("State", "OK"); bagItem.Add("DNSServers", dnsServers); bagItem.Add("Error", errorList); bagItem.Add("IP", ipAddressesText); } } result.Add(new PropertyBagDataItem(null, new Dictionary <string, Dictionary <string, object> > { { string.Empty, bagItem } })); return(result.ToArray()); }