public ParseIPListsCSV ParsedIPLists(string csvFile, string country) { ParseIPListsCSV parsedValues = new ParseIPListsCSV(); var mapRawData = new Dictionary <string, List <string> >(); int matchedLines = 0; int validLines = 0; using (StreamReader csvReader = new StreamReader(File.OpenRead(csvFile), true)) { string[] headers = GetHeaders(csvReader); foreach (string columnName in headers) { mapRawData[columnName] = new List <string>(); } while (!csvReader.EndOfStream) { var rawData = csvReader.ReadLine(); var dataValue = rawData.Split(','); var newFieldsList = new List <string>(dataValue); if (headers.Length == dataValue.Length) { if (dataValue[1].Contains(country)) { // Library.WriteErrorLog(logFilePath,"dataValue[1] " + dataValue[1] + " country " + country); int j = 0; foreach (string columnName in headers) { mapRawData[columnName].Add(dataValue[j]); j++; } validLines++; } } matchedLines++; } parsedValues.headers = headers; parsedValues.mappedData = mapRawData; parsedValues.matchedLines = validLines; } return(parsedValues); }
public ParseScanEngine GetScanEngineDetails(string ipListString, string country, int thread) { ParseScanEngine parsedValues = new ParseScanEngine(); Dictionary <string, string> mappedIPScanEngine = new Dictionary <string, string>(); List <string> scanEngineList = new List <string>(); String[] ip = ipListString.Split(','); //Library.WriteErrorLog(logFilePath, "Thread " + thread + ": Start to get Scan Engine details."); Llog.Info("Thread " + thread + ": Start to get Scan Engine details."); ParseIPListsCSV parsedData = ParsedIPLists(includedFilePath, country); for (int i = 0; i < ip.Length - 1; i++) { // Library.WriteErrorLog(logFilePath, "parsedData.matchedLines " + parsedData.matchedLines); for (int j = 0; j < parsedData.matchedLines; j++) { string siteID = parsedData.mappedData["SiteID"].ToArray()[j]; string siteName = parsedData.mappedData["SiteName"].ToArray()[j]; string rangeStart = parsedData.mappedData["RangeStart"].ToArray()[j]; string rangeEnd = parsedData.mappedData["RangeEnd"].ToArray()[j]; string scanEngine = parsedData.mappedData["ScanEngine"].ToArray()[j]; if (rangeEnd == "\"\"") { rangeEnd = rangeStart; } if (IsInRange(rangeStart, rangeEnd, ip[i])) { scanEngineList.Add(scanEngine); if (!mappedIPScanEngine.ContainsKey(ip[i])) { // Library.WriteErrorLog(logFilePath, "IP[i] " + ip[i]); mappedIPScanEngine.Add(ip[i], scanEngine); } break; } } } parsedValues.scanEngineList = scanEngineList; parsedValues.mappedIPScanEngine = mappedIPScanEngine; return(parsedValues); }