public bool ReadcsvBeacon(string csvFileName) { beaconInfoList.Clear(); CsvFileReader csvFileRd = new CsvFileReader(csvFileName, Encoding.UTF8, ';'); int count = csvFileRd.RowCount; if (count <= 2) { TraceMethod.RecordInfo($"Warning: {csvFileName} line number <=2, can't get beacon info."); return(false); } List <List <string> > data = csvFileRd.GetData(1, count); //get csv data List <string> headList = data[0]; for (int idx = 0; idx < headList.Count(); ++idx) { headList[idx] = headList[idx].ToLower(); } Func <string, int, string> readcsv = (colName, row) => { int col = headList.IndexOf(colName.ToLower()); if (1 <= col) { return(data[row][col].Trim()); } return(""); }; Func <string, int, Restriction, int> readintcsv = (colName, row, restri) => { string buff = readcsv(colName, row); int val = int.Parse(buff); if (restri.Validate(buff, colName) == false) { throw new Exception($"[{colName}] is invalid, read {buff}"); } return(val); }; //get first beacon line int start = 2; for (int i = 1; i <= count; ++i) { bool isNote = false; if (data[i][0].ToUpper() == "V") { for (int j = 0; j < csvFileRd.ColCount; ++j) { if (data[i][j].StartsWith("\"")) { isNote = true; break; } } } if (false == isNote) { start = i; break; } } //get restriction info Restriction res = new Restriction(@"./Config/Restriction.xml"); res.SetParentPath("BEACON_LAYOUT"); //for each line for (int i = start; i < count; ++i) { //check start if (data[i][0].ToUpper() == "V") { BeaconLayout beacon = new BeaconLayout(); try { beacon.Name = readcsv("Beacon_Name", i); beacon.BeaconVersion = readintcsv("Beacon_Version", i, res); beacon.ID = readintcsv("Beacon_ID", i, res); beacon.TrackID = readintcsv("Track_ID", i, res); beacon.kp = new KP_V(); // kp in csv file = finally kp beacon.kp.Value = new StringData(DataOpr.Multi100(readcsv("Kp", i))); beacon.BeaconBM = readintcsv("Beacon_Block_Mode", i, res); } catch (Exception ex) { TraceMethod.Record(TraceMethod.TraceKind.ERROR, $"Warning:load layout beacon {beacon.Name} fail {ex.Message}, ignore this beacon."); continue; } beaconInfoList.Add(beacon); } } if (0 == beaconInfoList.Count()) { return(false); } return(true); }