private void AddNewHost(string hostname, string rootDomain) { var host = new HostNode { Id = this.HostIDSeed, Host = rootDomain, HostName = hostname }; HostsDictionary.Add(hostname.ToLower().Trim(), host); this.HostIDSeed++; }
/// <summary> /// serializes graph to output file /// </summary> public void WriteGML() { if (this.AllSessions.Count > 0) { this.HostsDictionary = new Dictionary <string, HostNode>(); this.Edges = new List <Edge>(); foreach (Session oS in this.AllSessions) { if (string.IsNullOrEmpty(oS.hostname)) { continue; } if (!HostsDictionary.ContainsKey(oS.hostname.ToLower().Trim())) { AddNewHost(oS.hostname, oS.host.GetRootDomain()); string referer = string.IsNullOrEmpty(oS.oRequest.headers["referer"].ToLower().Trim()) ? string.Empty : new System.Uri(oS.oRequest.headers["referer"].ToLower().Trim()).Host; if (!string.IsNullOrEmpty(referer) && !referer.Contains(oS.hostname.Replace("www.", "").ToLower().Trim())) { AddEdges(oS, referer); } } else if (!string.IsNullOrEmpty(oS.oRequest.headers["referer"]) && !this.Edges.Any(e => e.RefererHostName.Equals(new System.Uri(oS.oRequest.headers["referer"].ToLower().Trim()).Host) && e.TargetHostName.Equals(oS.hostname.ToLower().Trim())) && !new System.Uri(oS.oRequest.headers["referer"].ToLower().Trim()).Host.Contains(oS.hostname.Replace("www.", "").ToLower().Trim())) { AddEdges(oS, new System.Uri(oS.oRequest.headers["referer"].ToLower().Trim()).Host); } } Utils.Serialize(HostsDictionary, this.Edges, this.OutputFiles, this.Directed); } }