Exemplo n.º 1
0
        public void NetworksWithLocationsToTsv(string inputFolderPath, string outputFilePath)
        {
            var outputFolderPath = Path.GetDirectoryName(outputFilePath);

            if (!Directory.Exists(outputFolderPath))
            {
                Directory.CreateDirectory(outputFolderPath);
            }

            var parser             = new WhoisParser(new SectionTokenizer(), new SectionParser());
            var locationExtraction = new NetworkLocationExtraction(parser);

            using (var outputFile = new StreamWriter(outputFilePath))
            {
                foreach (var inputFilePath in Directory.GetFiles(inputFolderPath))
                {
                    foreach (var network in locationExtraction.ExtractNetworksWithLocations(inputFilePath, inputFilePath))
                    {
                        if (network.Id != null)
                        {
                            var networkTsv = network.ToLocationTsv();
                            outputFile.WriteLine(networkTsv);
                        }
                        //// TODO: else log
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected void NetworksWithLocationsToTsv(WhoisParser parser, string inputFilePath, string outputFilePath)
        {
            var outputFolderPath = Path.GetDirectoryName(outputFilePath);

            if (!Directory.Exists(outputFolderPath))
            {
                Directory.CreateDirectory(outputFolderPath);
            }

            var locationExtraction = new NetworkLocationExtraction(parser);

            using (var outputFile = new StreamWriter(outputFilePath))
            {
                foreach (var network in locationExtraction.ExtractNetworksWithLocations(inputFilePath, inputFilePath))
                {
                    if (network.Id != null && network.Location.AddressSeemsValid())
                    {
                        var networkTsv = network.ToLocationTsv();
                        outputFile.WriteLine(networkTsv);
                    }
                    //// TODO: Else log
                }
            }
        }
Exemplo n.º 3
0
        protected void NetworksLocationPropertyCountsToTsv(WhoisParser parser, string inputFilePath, string propertyName, string outputFilePath)
        {
            var outputFolderPath = Path.GetDirectoryName(outputFilePath);

            if (!Directory.Exists(outputFolderPath))
            {
                Directory.CreateDirectory(outputFolderPath);
            }

            var locationExtraction = new NetworkLocationExtraction(parser);

            var stringsCount = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);

            var normalizedLocationType = typeof(NormalizedLocation);
            var properties             = normalizedLocationType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            PropertyInfo targetProperty = null;

            foreach (var property in properties)
            {
                if (property.Name == propertyName)
                {
                    targetProperty = property;
                }
            }

            if (targetProperty == null)
            {
                throw new ArgumentNullException("targetProperty");
            }

            foreach (var network in locationExtraction.ExtractNetworksWithLocations(inputFilePath, inputFilePath))
            {
                if (network.Id != null)
                {
                    var rawPropertyValue = targetProperty.GetValue(network.Location);

                    if (rawPropertyValue != null)
                    {
                        var value = (string)rawPropertyValue;

                        int currentCount;

                        if (!stringsCount.TryGetValue(value, out currentCount))
                        {
                            currentCount = 0;
                        }

                        currentCount++;
                        stringsCount[value] = currentCount;
                    }
                }
                //// TODO: Else log
            }

            using (var outputFile = new StreamWriter(outputFilePath))
            {
                foreach (var entry in stringsCount)
                {
                    // No need to sanitize entry.Value since it's a number
                    outputFile.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}\t{1}", TsvUtils.ReplaceAndTrimIllegalCharacters(entry.Key, removeDoubleQuotes: true), entry.Value));
                }
            }
        }