public static ConcurrentBag <Inspection> AddInspectionDateAndNumViolations(ConcurrentBag <Inspection> inspections) { Parallel.ForEach(inspections, i => { var cI = Inspections.CleanInspection(i.Page); var regx = new Regex(@"\b\w\w\w\w?\w?\w?\w?\w?\w?\w?\.?\s?\s?\d?\d,\s?\s?\d\d\d\d").Match(cI); var startDateString = regx.Value.Replace(".", "").Replace("Sept", "Sep"); DateTime startDate; if (DateTime.TryParse(startDateString, out startDate)) { i.InspectionStart = startDate; } else { i.InspectionStart = DateTime.MinValue; } int count = new Regex(@"Standard #").Matches(i.Page).Count; i.NumViolations = count; Console.WriteLine(i.FacilityLicID + ":" + i.InspectionID + ":" + i.NumViolations); } ); return(inspections); }
static void Main(string[] args) { //var facRecords = Inspections.GetLicInspectionIDs(); //var inspRecords = Inspections.BuildLicInspectionIDList(facRecords); //Inspections.GetInspectionRecords(inspRecords); var inspections = Inspections.GetInspections(); var inspectionWithDatesAndNumViolations = Inspections.AddInspectionDateAndNumViolations(inspections); var updatedRows = Inspections.UpdateInspections(inspectionWithDatesAndNumViolations); Console.WriteLine(updatedRows); }