//This takes in a new gpx file and creates a new GPXLog object which contains a list of HotSpot objects. List<HotSpot> readFile(string fn, List<HotSpot> hs) { List<HotSpot> data = hs; StreamReader sr = null; sr = new StreamReader(File.OpenRead(fn)); string currentLine = sr.ReadLine(); //look for beginning of xml while (!currentLine.Contains("<?xml")) currentLine = sr.ReadLine(); string lat = "", lon = "", ele = "", tim = "", geo = "", nam = "", cmt = "", des = "", fix = "", sat = "", hdo = "", vdo = "", pdo = "", mac = "", ssi = "", rss = "", cha = "", sec = "", sig = "", net = "", rat = ""; //loop through entire doc pulling out all records into a HotSpot list while (currentLine != "</gpx>") { currentLine = currentLine.Trim(); if (currentLine.StartsWith("<wpt lat")) { int p1 = currentLine.IndexOf("lat") + 5; int p2 = currentLine.IndexOf("\"", p1); lat = currentLine.Substring(p1, p2 - p1); int q1 = currentLine.IndexOf("lon") + 5; int q2 = currentLine.IndexOf("\"", q1); lon = currentLine.Substring(q1, q2 - q1); } else if (currentLine.StartsWith("<ele>")) { int p = currentLine.IndexOf("</ele>"); ele = currentLine.Substring(5, p - 5); } else if (currentLine.StartsWith("<time>")) { int p = currentLine.IndexOf("</time>"); tim = currentLine.Substring(6, p - 6); } else if (currentLine.StartsWith("<geoidheight>")) { int p = currentLine.IndexOf("</geoidheight>"); geo = currentLine.Substring(13, p - 13); } else if (currentLine.StartsWith("<name>")) { int p = currentLine.IndexOf("</name>"); nam = currentLine.Substring(6, p - 6); } else if (currentLine.StartsWith("<cmt>")) { int p = currentLine.IndexOf("</cmt>"); cmt = currentLine.Substring(5, p - 5); } else if (currentLine.StartsWith("<desc>")) { des = (currentLine.Substring(6) + "\n"); while (!currentLine.Contains("</desc>")) { currentLine = sr.ReadLine(); des += (currentLine + "\n"); } int p = currentLine.IndexOf("</desc>"); } else if (currentLine.StartsWith("<fix>")) { int p = currentLine.IndexOf("</fix>"); fix = currentLine.Substring(5, p - 5); } else if (currentLine.StartsWith("<sat>")) { int p = currentLine.IndexOf("</sat>"); sat = currentLine.Substring(5, p - 5); } else if (currentLine.StartsWith("<hdop>")) { int p = currentLine.IndexOf("</hdop>"); hdo = currentLine.Substring(6, p - 6); } else if (currentLine.StartsWith("<vdop>")) { int p = currentLine.IndexOf("</vdop>"); vdo = currentLine.Substring(6, p - 6); } else if (currentLine.StartsWith("<pdop>")) { int p = currentLine.IndexOf("</pdop>"); pdo = currentLine.Substring(6, p - 6); } else if (currentLine.StartsWith("<MAC>")) { int p = currentLine.IndexOf("</MAC>"); mac = currentLine.Substring(5, p - 5); } else if (currentLine.StartsWith("<SSID>")) { int p = currentLine.IndexOf("</SSID>"); ssi = currentLine.Substring(6, p - 6); } else if (currentLine.StartsWith("<RSSI>")) { int p = currentLine.IndexOf("</RSSI>"); rss = currentLine.Substring(6, p - 6); } else if (currentLine.StartsWith("<ChannelID>")) { int p = currentLine.IndexOf("</ChannelID>"); cha = currentLine.Substring(11, p - 11); } else if (currentLine.StartsWith("<security>")) { int p = currentLine.IndexOf("</security>"); sec = currentLine.Substring(10, p - 10); } else if (currentLine.StartsWith("<signalQuality>")) { int p = currentLine.IndexOf("</signalQuality>"); sig = currentLine.Substring(15, p - 15); } else if (currentLine.StartsWith("<networkType>")) { int p = currentLine.IndexOf("</networkType>"); net = currentLine.Substring(13, p - 13); } else if (currentLine.StartsWith("<rates>")) { int p = currentLine.IndexOf("</rates>"); rat = currentLine.Substring(7, p - 7); } else if (currentLine.Equals("</wpt>")) { //create hs object and add it to the brainz HotSpot temp = new HotSpot(lat, lon, ele, tim, geo, nam, cmt, des, fix, sat, hdo, vdo, pdo, mac, ssi, rss, cha, sec, sig, net, rat); data.Add(temp); lat = ""; lon = ""; ele = ""; tim = ""; geo = ""; nam = ""; cmt = ""; des = ""; fix = ""; sat = ""; hdo = ""; vdo = ""; pdo = ""; mac = ""; ssi = ""; rss = ""; cha = ""; sec = ""; sig = ""; net = ""; rat = ""; //MessageBox.Show(hs.getCompiledHS()); } currentLine = sr.ReadLine(); } sr.Dispose(); return data; }
//adds a HotSpot object to the data public void addHotSpot(HotSpot hs) { theData.Add(hs); }