public static GraphMapData JsonToGraph(TracWrapper tracWrapper) { if (tracWrapper == null) { throw new ArgumentNullException(); } GraphMapData graph = new GraphMapData(); IconNodeMapData seedNode = SeedToNode(tracWrapper.trac.result.seed); graph.Add(seedNode); // by definition Data are guaranteed to not have been seen yet foreach (Data data in tracWrapper.trac.result.datas) { IconNodeMapData dataNode = DataToNode(data); graph.Add(dataNode); EdgeMapData edgeToSeed = new EdgeMapData(seedNode.Id, dataNode.Id); graph.Add(edgeToSeed); // by definition Contact may have already been seen if (data.contacts != null) { foreach (Data contact in data.contacts) { if (!contact.address.Equals(seedNode.Id)) { NodeMapData contactNode; bool nodeAlreadyExists = graph.TryGetNode(contact.address, out contactNode); if (!nodeAlreadyExists) { contactNode = DataToNode(contact); graph.Add(contactNode); } EdgeMapData edgeToData = new EdgeMapData(dataNode.Id, contactNode.Id); graph.Add(edgeToData); } } } } return(graph); }