private void ClearData() { IsValid = false; FirstPassRefDesDict.Clear(); FirstPassPnDict.Clear(); FirstPassPnDups.Clear(); SecondPassRefDesDict.Clear(); SecondPassPnDict.Clear(); SecondPassPnDups.Clear(); Lines.Clear(); }
private void ParseFile() { Regex reProgramLine = new Regex(@"^\\par\s+Program:.*Date.*\\tab\s(\\tab\s)?([a-zA-z0-9\-_\s]+|Hand Place)\\tab\sSide:\s(SMT 1|SMT 2)"); Regex rePartNumLine = new Regex(@"^\\par (\S+)\\tab"); Regex reLocationLine = new Regex(@"( SL |Tray | SH |Hand Place)"); Regex reMultiLineRds = new Regex(@"\\tab \\tab \\tab "); string machine = null; string pass = null; string tempPart = null; string firstRefs = null; bool bGetLocation = false; bool bRefDesSearch = false; foreach (string line in Lines) { string templine = line; string part = null; if (line.Contains("REFERENCE DESIGNATOR COUNT")) { break; } if (bGetLocation) { string[] sep = { @"\tab " }; List <string> LocAndRefInfo = line.Split(sep, StringSplitOptions.None).ToList(); Match match = reLocationLine.Match(line); if (!match.Success) { continue; } List <string> lstLoc = GetLocAndRd(line); ///Added filter 2/12/2019 to account for old setup sheets containing SH (Shuttle) in the higher Fuzion slots ///This is an error in JohnCo legacy software that incorrectly assumes any slot above 100 must be a shuttle ///That was only the case on older equipment. The basically searches and replaces those incorrect SH's with SL's (Slot) /// string tempLocation = lstLoc.First(); if (machine.StartsWith("F") && Regex.Match(tempLocation, @"^SH\s").Success) { tempLocation = Regex.Replace(tempLocation, @"^SH\s", "SL "); } ///Tack on slot location to end of pn info list /// if (pass.Equals("SMT 1")) { FirstPassPnDict[tempPart].Add(tempLocation); } else { SecondPassPnDict[tempPart].Add(tempLocation); } firstRefs = lstLoc.Last(); bRefDesSearch = true; } if (bRefDesSearch) { if (bGetLocation) { bGetLocation = false; List <string> fRefs = firstRefs.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); firstRefs = null; if (pass.Equals("SMT 1")) { string fdrLocation = FirstPassPnDict[tempPart].Last(); foreach (var rd in fRefs) { if (FirstPassRefDesDict.ContainsKey(rd)) { if (!string.IsNullOrEmpty(rd) && !string.IsNullOrWhiteSpace(rd)) { if (DuplicateRefs.ContainsKey(rd)) { DuplicateRefs[rd].Add(tempPart); } else { DuplicateRefs.Add(rd, new List <string> { FirstPassRefDesDict[rd][0], tempPart }); } } } else { FirstPassRefDesDict[rd] = new List <string> { tempPart, pass, machine, fdrLocation } }; } continue; } else { string fdrLocation = SecondPassPnDict[tempPart].Last(); foreach (var rd in fRefs) { if (SecondPassRefDesDict.ContainsKey(rd)) { if (!string.IsNullOrEmpty(rd) && !string.IsNullOrWhiteSpace(rd)) { if (DuplicateRefs.ContainsKey(rd)) { DuplicateRefs[rd].Add(tempPart); } else { DuplicateRefs.Add(rd, new List <string> { SecondPassRefDesDict[rd][0], tempPart }); } } } else { SecondPassRefDesDict[rd] = new List <string> { tempPart, pass, machine, fdrLocation } }; } continue; } } else { Match matchRds = reMultiLineRds.Match(line); if (!matchRds.Success && rePartNumLine.Match(line).Success) { bRefDesSearch = false; } else if (matchRds.Success) { List <string> lstRds = reMultiLineRds.Split(line).Last().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (pass.Equals("SMT 1")) { string fdrLocation = FirstPassPnDict[tempPart].Last(); foreach (var rd in lstRds) { if (FirstPassRefDesDict.ContainsKey(rd) && !string.IsNullOrWhiteSpace(rd)) { if (!string.IsNullOrEmpty(rd) && !string.IsNullOrWhiteSpace(rd)) { if (DuplicateRefs.ContainsKey(rd)) { DuplicateRefs[rd].Add(tempPart); } else { DuplicateRefs.Add(rd, new List <string> { FirstPassRefDesDict[rd][0], tempPart }); } } } else { FirstPassRefDesDict[rd] = new List <string> { tempPart, pass, machine, fdrLocation } }; } continue; } else { string fdrLocation = SecondPassPnDict[tempPart].Last(); foreach (var rd in lstRds) { if (SecondPassRefDesDict.ContainsKey(rd) && !string.IsNullOrEmpty(rd)) { if (!string.IsNullOrEmpty(rd) && !string.IsNullOrWhiteSpace(rd)) { if (DuplicateRefs.ContainsKey(rd)) { DuplicateRefs[rd].Add(tempPart); } else { DuplicateRefs.Add(rd, new List <string> { SecondPassRefDesDict[rd][0], tempPart }); } } } else { SecondPassRefDesDict[rd] = new List <string> { tempPart, pass, machine, fdrLocation } }; } continue; } } } } Match m = reProgramLine.Match(line); if (m.Success) { ///Grab machine and pass whenever available /// machine = m.Groups[2].Value; pass = m.Groups[3].Value; ///Strip hyphens and underscores to account for different naming styles /// string[] removechars = new string[] { "-", "_" }; foreach (string c in removechars) { machine = machine.Replace(c, string.Empty); } ///added if-if-else below on 2/12/2019 to clean results file incorrectly calling out location mismatch - gc60_1 vs gc60 (s/b ==) if (machine.Equals("GI141")) { machine = "GI14"; } else if (machine.Equals("GC601")) { machine = "GC60"; } continue; } m = rePartNumLine.Match(line); if (m.Success) { part = m.Groups[1].Value; string feeder = GetFeederType(line); if (pass.Equals("SMT 1")) { if (!FirstPassPnDict.ContainsKey(part)) { FirstPassPnDict.Add(part, new List <string>(new string[] { feeder, pass, machine })); tempPart = part; bGetLocation = true; } else { if (!FirstPassPnDups.ContainsKey(part)) { FirstPassPnDups.Add(part, new List <string>(new string[] { feeder, pass, machine })); } else { FirstPassPnDups[part].AddRange(new List <string>(new string[] { feeder, pass, machine })); } } } else { if (!SecondPassPnDict.ContainsKey(part)) { SecondPassPnDict.Add(part, new List <string>(new string[] { feeder, pass, machine })); tempPart = part; bGetLocation = true; } else { if (!SecondPassPnDups.ContainsKey(part)) { SecondPassPnDups.Add(part, new List <string>(new string[] { feeder, pass, machine })); } else { SecondPassPnDups[part].AddRange(new List <string>(new string[] { feeder, pass, machine })); } } } } } }