private void btnParseFile_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtGeoIpInputFile.Text)) { MessageBox.Show("No input file selected!"); return; } txtGeoIpStatus.Text = "Reading file..."; ipLocationList = IpLocation.ParseInputFile(txtGeoIpInputFile.Text); txtGeoIpStatus.Text = ipLocationList.Count + " items loaded"; }
public static List <IpLocation> ParseInputFile(string fileName) { List <IpLocation> retList = new List <IpLocation>(); try { FileStream stream = File.OpenRead(fileName); StreamReader sr = new StreamReader(stream); string rowData; while (!sr.EndOfStream) { rowData = sr.ReadLine(); if (rowData.Length > 0 && rowData[0] != '#') { string[] rowDataArr = parseToArr(rowData); if (rowDataArr.Length == 7) { try { IpLocation ipLoc = new IpLocation(); ipLoc.IpFrom = long.Parse(rowDataArr[0]); ipLoc.IpTo = long.Parse(rowDataArr[1]); ipLoc.Registry = rowDataArr[2]; ipLoc.Assigned = long.Parse(rowDataArr[3]); ipLoc.Ctry = rowDataArr[4]; ipLoc.Cntry = rowDataArr[5]; ipLoc.Country = rowDataArr[6]; retList.Add(ipLoc); } catch { } } } } } catch { } return(retList); }