CheckForLowDetectorHits(Models.Signal signal) { var detectors = signal.GetDetectorsForSignalThatSupportAMetric(6); //Parallel.ForEach(detectors, options, detector => foreach (var detector in detectors) { try { if (detector.DetectionTypes != null && detector.DetectionTypes.Any(d => d.DetectionTypeID == 2)) { var channel = detector.DetChannel; var direction = detector.Approach.DirectionType.Description; var start = new DateTime(); var end = new DateTime(); if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { start = ScanDate.AddDays(-3).Date.AddHours(Settings.PreviousDayPMPeakStart); end = ScanDate.AddDays(-3).Date.AddHours(Settings.PreviousDayPMPeakEnd); } else { start = ScanDate.AddDays(-1).Date.AddHours(Settings.PreviousDayPMPeakStart); end = ScanDate.AddDays(-1).Date.AddHours(Settings.PreviousDayPMPeakEnd); } var currentVolume = detector.GetVolumeForPeriod(start, end); //Compare collected hits to low hit threshold, if (currentVolume < Convert.ToInt32(Settings.LowHitThreshold)) { var error = new SPMWatchDogErrorEvent(); error.SignalID = signal.SignalID; error.DetectorID = detector.DetectorID; error.Phase = detector.Approach.ProtectedPhaseNumber; error.TimeStamp = ScanDate; error.Direction = detector.Approach.DirectionType.Description; error.Message = "CH: " + channel.ToString() + " - Count: " + currentVolume.ToString(); error.ErrorCode = 2; if (!LowHitCountErrors.Contains(error)) { LowHitCountErrors.Add(error); } } } } catch (Exception ex) { var er = ApplicationEventRepositoryFactory.Create(); er.QuickAdd("SPMWatchDog", "Program", "CheckForLowDetectorHits", ApplicationEvent.SeverityLevels.Medium, detector.DetectorID + "-" + ex.Message); } } //); }
private void GetRecordCountForWeekDayAndWeekend(Signal signal) { if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { CheckSignalRecordCount(ScanDate.AddDays(-2), signal); } else { CheckSignalRecordCount(ScanDate, signal); } }
private void CheckForRecords(List <Models.Signal> signals) { var options = new ParallelOptions(); options.MaxDegreeOfParallelism = Settings.MaxDegreeOfParallelism; Parallel.ForEach(signals, options, signal => { if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { CheckSignalRecordCount(ScanDate.AddDays(-2), signal); } else { CheckSignalRecordCount(ScanDate, signal); } }); }
private string SortAndAddToMessage(ConcurrentBag <SPMWatchDogErrorEvent> errors) { var watchDogErrorEventRepository = SPMWatchDogErrorEventRepositoryFactory.Create(); var SortedErrors = errors.OrderBy(x => x.SignalID).ThenBy(x => x.Phase).ToList(); var ErrorMessage = ""; foreach (var error in SortedErrors) { if (!Settings.EmailAllErrors) { //List<SPMWatchDogErrorEvent> RecordsFromTheDayBefore = new List<SPMWatchDogErrorEvent>(); //compare to error log to see if this was failing yesterday if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { RecordsFromTheDayBefore = watchDogErrorEventRepository.GetSPMWatchDogErrorEventsBetweenDates(ScanDate.AddDays(-3), ScanDate.AddDays(-2).AddMinutes(-1)); } else { RecordsFromTheDayBefore = watchDogErrorEventRepository.GetSPMWatchDogErrorEventsBetweenDates(ScanDate.AddDays(-1), ScanDate.AddMinutes(-1)); } } if (Settings.EmailAllErrors || FindMatchingErrorInErrorTable(error) == false) { var signalRepository = SignalsRepositoryFactory.Create(); var signal = signalRepository.GetLatestVersionOfSignalBySignalID(error.SignalID); // Add to email if it was not failing yesterday ErrorMessage += error.SignalID; ErrorMessage += " - "; ErrorMessage += signal.PrimaryName; ErrorMessage += " & "; ErrorMessage += signal.SecondaryName; if (error.Phase > 0) { ErrorMessage += " - Phase "; ErrorMessage += error.Phase; } ErrorMessage += " (" + error.Message + ")"; ErrorMessage += "\n"; } } try { watchDogErrorEventRepository.AddListAndSaveToDatabase(errors.ToList()); } catch (DbEntityValidationException ex) { foreach (var entityValidationErrors in ex.EntityValidationErrors) { foreach (var validationError in entityValidationErrors.ValidationErrors) { Console.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage); } } } return(ErrorMessage); }
private void CreateAndSendEmail() { var message = new MailMessage(); var db = new SPM(); var userStore = new UserStore <SPMUser>(db); var userManager = new UserManager <SPMUser>(userStore); var users = (from u in userManager.Users where u.ReceiveAlerts select u).ToList(); foreach (var user in users) { message.To.Add(user.Email); } message.To.Add(Settings.DefaultEmailAddress); message.Subject = "ATSPM Alerts for " + ScanDate.ToShortDateString(); message.From = new MailAddress(Settings.FromEmailAddress); var missingErrors = SortAndAddToMessage(MissingRecords); var forceErrors = SortAndAddToMessage(ForceOffErrors); var maxErrors = SortAndAddToMessage(MaxOutErrors); var countErrors = SortAndAddToMessage(LowHitCountErrors); var stuckpedErrors = SortAndAddToMessage(StuckPedErrors); var ftpErrors = SortAndAddToMessage(CannotFtpFiles); if (MissingRecords.Count > 0 && missingErrors != "") { message.Body += " \n --The following signals had too few records in the database on "; if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { message.Body += ScanDate.AddDays(-3).Date.ToShortDateString() + ": \n"; } else { message.Body += ScanDate.AddDays(-1).Date.ToShortDateString() + ": \n"; } message.Body += missingErrors; } else { message.Body += "\n --No new missing record errors were found on "; if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { message.Body += ScanDate.AddDays(-3).Date.ToShortDateString() + ": \n"; } else { message.Body += ScanDate.AddDays(-1).Date.ToShortDateString() + ": \n"; } } if (ForceOffErrors.Count > 0 && forceErrors != "") { message.Body += " \n --The following signals had too many force off occurrences between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; message.Body += forceErrors; } else { message.Body += "\n --No new force off errors were found between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; } if (MaxOutErrors.Count > 0 && maxErrors != "") { message.Body += " \n --The following signals had too many max out occurrences between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; message.Body += maxErrors; } else { message.Body += "\n --No new max out errors were found between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; } if (LowHitCountErrors.Count > 0 && countErrors != "") { message.Body += " \n --The following signals had unusually low advanced detection counts on "; if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { message.Body += ScanDate.AddDays(-3).ToShortDateString() + " between "; } else { message.Body += ScanDate.AddDays(-1).ToShortDateString() + " between "; } message.Body += Settings.PreviousDayPMPeakStart + ":00 and " + Settings.PreviousDayPMPeakEnd + ":00: \n"; message.Body += countErrors; } else { message.Body += "\n --No new low advanced detection count errors on "; if (Settings.WeekdayOnly && ScanDate.DayOfWeek == DayOfWeek.Monday) { message.Body += ScanDate.AddDays(-3).ToShortDateString() + " between "; } else { message.Body += ScanDate.AddDays(-1).ToShortDateString() + " between "; } message.Body += Settings.PreviousDayPMPeakStart + ":00 and " + Settings.PreviousDayPMPeakEnd + ":00: \n"; } if (StuckPedErrors.Count > 0 && stuckpedErrors != "") { message.Body += " \n --The following signals have high pedestrian activation occurrences between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; message.Body += stuckpedErrors; } else { message.Body += "\n --No new high pedestrian activation errors between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; } if (CannotFtpFiles.Count > 0 && ftpErrors != "") { message.Body += " \n --The following signals have had FTP problems. central was not able to delete the file on the controller between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; message.Body += ftpErrors; } else { message.Body += "\n --No new controllers had problems FTPing files from the controller between " + Settings.ScanDayStartHour + ":00 and " + Settings.ScanDayEndHour + ":00: \n"; } SendMessage(message); }