Example #1
0
        public void HydrateParseResults([Option("p", "file to load parse results from")] string parseLocation,
                                        [Option("h", "file to load host information from")] string hostLocation,
                                        [Option("l", "file to load location information from")] string ipLocation,
                                        [Option("o", "file to write final results to")] string outputLocation
                                        )
        {
            var parseResults    = JsonSerializer.Deserialize <List <ParsingResult> >(File.ReadAllText(parseLocation));
            var hostResults     = JsonSerializer.Deserialize <Dictionary <string, HostInformation> >(File.ReadAllText(hostLocation));
            var locationResults = JsonSerializer.Deserialize <Dictionary <string, AddressInformation> >(File.ReadAllText(ipLocation));

            var results = new List <FinalResult>();

            foreach (var trace in parseResults)
            {
                hostResults.TryGetValue(trace.Host, out var hostInfo);
                locationResults.TryGetValue(trace.Address, out var addrInfo);
                var result = FinalResult.CreateFrom(trace, ResultMetadata.ComposeFrom(hostInfo, addrInfo));

                foreach (var hop in trace.Hops)
                {
                    hostResults.TryGetValue(hop.Host, out hostInfo);
                    locationResults.TryGetValue(hop.Address, out addrInfo);
                    var hopResult = ResultMetadata.ComposeFrom(hostInfo, addrInfo);
                    result.Hops.Add(FinalHop.CreateFrom(hop, hopResult));
                }

                results.Add(result);
            }

            File.WriteAllText(outputLocation + ".json", JsonSerializer.Serialize(results));
        }
 public static FinalResult CreateFrom(ParsingResult result, ResultMetadata metadata)
 {
     return(new FinalResult()
     {
         Host = result.Host,
         Address = result.Address,
         Metadata = metadata
     });
 }
Example #3
0
        public static FinalHop CreateFrom(Hop hop, ResultMetadata result)
        {
            var avg = (hop.Ping1 + hop.Ping2 + hop.Ping3) / 3;

            return(new FinalHop()
            {
                Host = hop.Host,
                Address = hop.Address,
                Metadata = result,
                Ping = avg
            });
        }