public static List <string> FindAllMatchingFieldValuesInRecords(RawWhoisSection section, HashSet <string> fields)
        {
            var results = new List <string>();

            if (section != null && fields != null)
            {
                foreach (var field in fields)
                {
                    StringBuilder nameBuilder;

                    if (section.Records.TryGetValue(field, out nameBuilder))
                    {
                        results.Add(nameBuilder.ToString());
                    }
                }
            }

            if (results.Count > 0)
            {
                return(results);
            }
            else
            {
                return(null);
            }
        }
 public static void ExtractCommonRecordMetadata(RawWhoisSection section, string id, HashSet <string> nameFieldNames, ICommonRecordMetadata target)
 {
     target.Id          = id;
     target.Name        = FindFirstMatchingFieldValueInRecords(section, nameFieldNames);
     target.Created     = FindOldestDateOptimized(FindFirstMatchingFieldValueInRecords(section, createdFields));
     target.Updated     = FindOldestDateOptimized(FindFirstMatchingFieldValueInRecords(section, updatedFields));
     target.UpdatedBy   = FindFirstMatchingFieldValueInRecords(section, updatedByFields);
     target.Description = FindFirstMatchingFieldValueInRecords(section, descriptionFields);
     target.Comment     = FindFirstMatchingFieldValueInRecords(section, commentFields);
     target.Source      = FindFirstMatchingFieldValueInRecords(section, sourceFields);
 }
        public static NormalizedLocation TryParseFromSection(RawWhoisSection section)
        {
            var location = new NormalizedLocation()
            {
                Address       = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, addressFields, allBlacklistedValues),
                Street        = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, streetFields, allBlacklistedValues),
                City          = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, cityFields, allBlacklistedValues),
                StateProvince = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, stateProvinceFields, allBlacklistedValues),
                PostalCode    = RemoveExtraPrefix(NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, postalCodeFields, allBlacklistedValues)),
                Country       = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, countryFields, blacklistedValuesExceptSimilarToCountries), // Not using blacklisted values because NA is a valid country
                Geolocation   = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, geolocationFields)
            };

            return(location);
        }
        public static NormalizedOrganization TryParseFromSection(RawWhoisSection section)
        {
            if (organizationTypes.Contains(section.Type))
            {
                var organization = new NormalizedOrganization()
                {
                    Location = NormalizedLocation.TryParseFromSection(section),
                    Phone    = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, phoneFields)
                };

                NormalizationUtils.ExtractCommonRecordMetadata(section, section.Id, nameFields, organization);

                return(organization);
            }

            return(null);
        }
        public void FindExternalOrganization(RawWhoisSection section, Dictionary <string, List <NormalizedOrganization> > organizations)
        {
            var candidateOrganizations = NormalizationUtils.FindAllMatchingFieldValuesInRecords(section, organizationFields);

            if (candidateOrganizations != null)
            {
                foreach (var candidateOrganization in candidateOrganizations)
                {
                    List <NormalizedOrganization> potentialOrganizations;

                    if (organizations.TryGetValue(candidateOrganization, out potentialOrganizations))
                    {
                        this.ExternalOrganization = potentialOrganizations.FirstOrDefault();
                        break;
                    }
                }
            }
        }
        public static NormalizedNetwork TryParseFromSection(RawWhoisSection section)
        {
            if (networkTypes.Contains(section.Type))
            {
                var network = new NormalizedNetwork()
                {
                    Location = NormalizedLocation.TryParseFromSection(section),
                    AuthArea = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, authAreaFields),
                    OriginAS = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, originASFields),
                    Status   = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, statusFields)
                };

                var candidateRanges = NormalizationUtils.FindAllMatchingFieldValuesInRecords(section, ipRangeFields);

                if (candidateRanges != null)
                {
                    IPAddressRange range = null;

                    foreach (var candidateRange in candidateRanges)
                    {
                        if (IPAddressRange.TryParse(candidateRange, out range))
                        {
                            break;
                        }
                    }

                    network.IPRange = range;
                }
                else
                {
                    // TODO: Some networks do not have an explicit IP range but maybe we can get it from the Auth Area or from the ID?
                }

                NormalizationUtils.ExtractCommonRecordMetadata(section, section.Id, nameFields, network);

                return(network);
            }

            return(null);
        }
        public static string FindFirstMatchingFieldValueInRecords(RawWhoisSection section, HashSet <string> fields, HashSet <string> blacklistedValues = null)
        {
            if (section != null && fields != null)
            {
                foreach (var field in fields)
                {
                    StringBuilder nameBuilder;

                    if (section.Records.TryGetValue(field, out nameBuilder))
                    {
                        var value = nameBuilder.ToString();

                        if (blacklistedValues == null || !blacklistedValues.Contains(value))
                        {
                            return(value);
                        }
                    }
                }
            }

            return(null);
        }