public void Remove(int approachID) { Approach approach = db.Approaches.Find(approachID); if (approach != null) { try { db.Approaches.Remove(approach); db.SaveChanges(); } catch (Exception ex) { { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRepository"; error.Function = "Remove"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw (ex); } } } }
public Models.ApproachRoute GetRouteByID(int routeID) { Models.ApproachRoute route = (from r in db.ApproachRoutes where r.ApproachRouteId == routeID select r).FirstOrDefault(); if (route != null) { return(route); } else { { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteRepository"; error.Function = "GetByRouteID"; error.Description = "No ApproachRoute for ID. Attempted ID# = " + routeID.ToString(); error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw (new Exception("There is no ApproachRoute for this ID")); } } }
public void UpdateByID(int routeID, string newDescription) { Models.ApproachRoute route = (from r in db.ApproachRoutes where r.ApproachRouteId == routeID select r).FirstOrDefault(); if (route != null) { Models.ApproachRoute newroute = new Models.ApproachRoute(); newroute.ApproachRouteId = route.ApproachRouteId; newroute.RouteName = newDescription; try { db.Entry(route).CurrentValues.SetValues(newroute); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteRepository"; error.Function = "UpdateByID"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
public MOE.Common.Models.Controller_Event_Log GetFirstEventBeforeDate(string signalID, int eventCode, DateTime date) { try { var events = (from s in db.Controller_Event_Log where s.SignalID == signalID && s.Timestamp >= date.AddDays(-1) && s.Timestamp < date && s.EventCode == eventCode select s).ToList(); events.Sort((x, y) => DateTime.Compare(x.Timestamp, y.Timestamp)); return(events.Last()); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = this.GetType().ToString(); e.Function = "GetEventsByEventCodesParamWithOffset"; e.SeverityLevel = MOE.Common.Models.ApplicationEvent.SeverityLevels.High; e.Description = ex.Message; e.Timestamp = DateTime.Now; logRepository.Add(e); throw; } }
public List <MOE.Common.Models.Controller_Event_Log> GetSignalEventsBetweenDates(string signalID, DateTime startTime, DateTime endTime) { try { return((from r in db.Controller_Event_Log where r.SignalID == signalID && r.Timestamp >= startTime && r.Timestamp < endTime select r).ToList()); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = this.GetType().ToString(); e.Function = "GetSignalEventsBetweenDates"; e.SeverityLevel = MOE.Common.Models.ApplicationEvent.SeverityLevels.High; e.Timestamp = DateTime.Now; e.Description = ex.Message; logRepository.Add(e); throw; } }
public List <MOE.Common.Models.Controller_Event_Log> GetEventsByEventCodesParamWithOffset(string signalID, DateTime startTime, DateTime endTime, List <int> eventCodes, int param, double offset) { try { var events = (from s in db.Controller_Event_Log where s.SignalID == signalID && s.Timestamp >= startTime && s.Timestamp <= endTime && s.EventParam == param && eventCodes.Contains(s.EventCode) select s).ToList(); events.Sort((x, y) => DateTime.Compare(x.Timestamp, y.Timestamp)); foreach (var cel in events) { cel.Timestamp = cel.Timestamp.AddMilliseconds(offset); } return(events); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent(); e.ApplicationName = "MOE.Common"; e.Class = this.GetType().ToString(); e.Function = "GetEventsByEventCodesParamWithOffset"; e.SeverityLevel = MOE.Common.Models.ApplicationEvent.SeverityLevels.High; e.Timestamp = DateTime.Now; e.Description = ex.Message; logRepository.Add(e); throw; } }
public void UpdateByRouteAndApproachID(int routeID, int approachID, int newOrderNumber) { Models.ApproachRouteDetail RouteDetail = (from r in db.ApproachRouteDetails where r.ApproachRouteId == routeID && r.ApproachID == approachID select r).FirstOrDefault(); if (RouteDetail != null) { Models.ApproachRouteDetail newRouteDetail = new Models.ApproachRouteDetail(); newRouteDetail.ApproachOrder = newOrderNumber; try { db.Entry(RouteDetail).CurrentValues.SetValues(newRouteDetail); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteDetailsRepository"; error.Function = "UpdateByRouteAndApproachID"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
public void DeleteByRouteID(int routeID) { List <Models.ApproachRouteDetail> routes = (from r in db.ApproachRouteDetails where r.ApproachRouteId == routeID select r).ToList(); try { db.ApproachRouteDetails.RemoveRange(routes); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteDetailsRepository"; error.Function = "DeleteByRouteID"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } }
public Models.Approach GetApproachByApproachID(int approachID) { var approach = (from r in db.Approaches where r.ApproachID == approachID select r); if (approach != null) { return(approach.FirstOrDefault()); } else { { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRepository"; error.Function = "GetApproachByApproachID"; error.Description = "No approach for ID. Attempted ID# = " + approachID.ToString(); error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw(new Exception("There is no Approach for this ID")); } } }
public MOE.Common.Business.TMC.TMCInfo CreateTMCChart(MOE.Common.Business.WCFServiceLibrary.TMCOptions options) { try { MOE.Common.Models.Repositories.IMetricTypeRepository metricTypeRepository = MOE.Common.Models.Repositories.MetricTypeRepositoryFactory.Create(); options.MetricType = metricTypeRepository.GetMetricsByID(options.MetricTypeID); options.CreateMetric(); return(options.TmcInfo); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent(); e.ApplicationName = "MOEWCFServicLibrary"; e.Class = this.GetType().ToString(); e.Function = "CreateMetric"; e.SeverityLevel = MOE.Common.Models.ApplicationEvent.SeverityLevels.High; e.Description = ex.Message; e.Timestamp = DateTime.Now; logRepository.Add(e); throw; } //return options.MetricInfoList; }
public ActionResult GetApproachVolumeMetric(MOE.Common.Business.WCFServiceLibrary.ApproachVolumeOptions metricOptions) { MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MetricInfo[] metrics = null; //metricOptions.MetricType = GetMetricType(metricOptions.MetricTypeID); //string[] result = new string[1] { "" }; if (ModelState.IsValid) { MetricGeneratorService.MetricGeneratorClient client = new MetricGeneratorService.MetricGeneratorClient(); try { client.Open(); metrics = client.CreateMetricWithDataTable((ApproachVolumeOptions)metricOptions); client.Close(); } catch (Exception ex) { client.Close(); return(Content("<h1>" + ex.Message + "</h1>")); } } return(PartialView("GetApproachVolumeMetric", metrics)); }
static void Main(string[] args) { DateTime StartTime = DateTime.Today; // find the analysis timespan if (args.Length > 0) { try { StartTime = DateTime.Parse(args[0]); MOE.Common.Business.WatchDog.WatchDogScan scan = new MOE.Common.Business.WatchDog.WatchDogScan(StartTime); scan.StartScan(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message); } } else { try { MOE.Common.Business.WatchDog.WatchDogScan scan = new MOE.Common.Business.WatchDog.WatchDogScan(StartTime); scan.StartScan(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message); } } }
public Detector Add(Models.Detector detector) { Models.Detector g = (from r in db.Detectors where r.ID == detector.ID select r).FirstOrDefault(); if (g == null) { detector.DetectionTypes = new List <DetectionType>(); detector.DetectionTypes = db.DetectionTypes.Where(dt => detector.DetectionTypeIDs.Contains(dt.DetectionTypeID)).ToList();; try { db.Detectors.Add(detector); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.DetectorRepository"; error.Function = "Add"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } return(detector); }
public void AddOrUpdate(MOE.Common.Models.Signal signal) { MOE.Common.Models.Signal g = (from r in db.Signals where r.SignalID == signal.SignalID select r).FirstOrDefault(); if (g == null) { db.Signals.Add(signal); try { db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.SignalRepository"; error.Function = "AddOrUpdate"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } else { Update(signal); //throw new Exception("Signal already exists in the database"); } }
public List <Tuple <string, string> > GetChartAndXmlFileLocations(MOE.Common.Business.WCFServiceLibrary.MetricOptions options) { try { MOE.Common.Models.Repositories.IMetricTypeRepository metricTypeRepository = MOE.Common.Models.Repositories.MetricTypeRepositoryFactory.Create(); options.MetricType = metricTypeRepository.GetMetricsByID(options.MetricTypeID); options.CreateMetric(); return(options.ResultChartAndXmlLocations); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent(); e.ApplicationName = "MOEWCFServicLibrary"; e.Class = this.GetType().ToString(); e.Function = "ExportMetricData"; e.SeverityLevel = MOE.Common.Models.ApplicationEvent.SeverityLevels.High; e.Description = ex.Message + ex.InnerException; e.Timestamp = DateTime.Now; logRepository.Add(e); throw; } }
public void Remove(int ID) { Models.Detector g = (from r in db.Detectors where r.ID == ID select r).FirstOrDefault(); if (g != null) { try { db.Detectors.Remove(g); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.DetectorRepository"; error.Function = "Remove"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
private void SendMessage(System.Net.Mail.MailMessage message) { MOE.Common.Models.Repositories.IApplicationEventRepository er = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["EmailServer"]); try { Console.WriteLine("Sent message to: " + message.To.ToString() + "\nMessage text: " + message.Body + "\n"); smtp.Send(message); System.Threading.Thread.Sleep(500); er.QuickAdd("ImportChecker", "Program", "SendMessage", MOE.Common.Models.ApplicationEvent.SeverityLevels.Information, "Email Sent Successfully to: " + message.To.ToString()); } catch (Exception ex) { try { er.QuickAdd("ImportChecker", "Program", "SendMessage", MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, ex.Message); } catch (Exception e) { Console.WriteLine(e); throw; } } }
//public List<MOE.Common.Business.ApproachVolume.MetricInfo> CreateMetricWithDataTable(MOE.Common.Business.WCFServiceLibrary.ApproachVolumeOptions options) //{ // List<string> result = new List<string>(); // try // { // options.CreateMetric(); // return options.TmcInfo; // } // catch (Exception ex) // { // MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = // MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); // MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent(); // e.ApplicationName = "MOEWCFServicLibrary"; // e.Class = this.GetType().ToString(); // e.Function = "CreateMetric"; // e.SeverityLevel = MOE.Common.Models.ApplicationEvent.SeverityLevels.High; // e.Description = ex.Message; // e.Timestamp = DateTime.Now; // logRepository.Add(e); // throw; // } // return options.MetricInfoList; //} public List <MOE.Common.Business.ApproachVolume.MetricInfo> CreateMetricWithDataTable(MOE.Common.Business.WCFServiceLibrary.ApproachVolumeOptions options) { List <string> result = new List <string>(); try { MOE.Common.Models.Repositories.IMetricTypeRepository metricTypeRepository = MOE.Common.Models.Repositories.MetricTypeRepositoryFactory.Create(); options.MetricType = metricTypeRepository.GetMetricsByID(options.MetricTypeID); result = options.CreateMetric(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository logRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent e = new MOE.Common.Models.ApplicationEvent(); e.ApplicationName = "MOEWCFServicLibrary"; e.Class = this.GetType().ToString(); e.Function = "CreateMetric"; e.SeverityLevel = MOE.Common.Models.ApplicationEvent.SeverityLevels.High; e.Description = ex.Message; e.Timestamp = DateTime.Now; logRepository.Add(e); throw; } return(options.MetricInfoList); }
public ActionResult ReportsRun(DateTime startDate, DateTime endDate) { MOE.Common.Models.ViewModel.MetricUsage.ChartViewModel reportData = GetChartViewModel("Reports Run", "ReportsRun", "# of Reports Run", "bar"); MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); var metrics = metricTypeRepository.GetAllToDisplayMetrics(); List <string> descriptions = new List <string>(); foreach (MetricType m in metrics) { descriptions.Add(m.ChartName + " Executed"); reportData.ChartData.Add(new MOE.Common.Business.ActionLog.ChartData { Description = m.ChartName, Value = 0 }); } var events = eventRepository.GetEventsByDateDescriptions(startDate, endDate, descriptions); foreach (ApplicationEvent ae in events) { var chartData = reportData.ChartData.Where(r => ae.Description == r.Description + " Executed").FirstOrDefault(); chartData.Value++; } SetColors(reportData); return(PartialView("Chart", reportData)); }
static void Main(string[] args) { DateTime startTime = DateTime.Today; // find the analysis timespan if (args.Length > 0) { try { startTime = DateTime.Parse(args[0]); MOE.Common.Business.WatchDog.WatchDogScan scan = new MOE.Common.Business.WatchDog.WatchDogScan(startTime); scan.StartScan(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); errorRepository.QuickAdd("SPMWatchdog", "WatchDog", "WatchDogScan with args", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message); } } else { try { MOE.Common.Business.WatchDog.WatchDogScan scan = new MOE.Common.Business.WatchDog.WatchDogScan(startTime); scan.StartScan(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository errorRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); errorRepository.QuickAdd("SPMWatchdog", "WatchDog", "WatchDogScan no args", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message); } } }
public List <Models.ApproachRouteDetail> GetByRouteID(int routeID) { List <Models.ApproachRouteDetail> routes = (from r in db.ApproachRouteDetails where r.ApproachRouteId == routeID select r).ToList(); if (routes.Count > 0) { return(routes); } else { { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteDetailsRepository"; error.Function = "GetByRouteID"; error.Description = "No ApproachRoute for ID. Attempted ID# = " + routeID.ToString(); error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw (new Exception("There is no ApproachRouteDetail for this ID")); } } }
private void ReceiveData(IAsyncResult asyncResult) { try { string senderIPaddress = asyncResult.AsyncState.ToString(); // Initialise a packet object to store the received data Packet receivedData = new Packet(this.dataStream, senderIPaddress); // Initialise the IPEndPoint for the clients IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0); // Initialise the EndPoint for the clients EndPoint epSender = (EndPoint)clients; // Receive all data serverSocket.EndReceiveFrom(asyncResult, ref epSender); // Listen for more connections again... serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None, ref epSender, new AsyncCallback(this.ReceiveData), epSender); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "RecieveData", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message); } }
public void StartListening() { try { // Initialise the IPEndPoint for the clients IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0); // Initialise the EndPoint for the clients EndPoint epSender = (EndPoint)clients; TcpListener listener = new TcpListener(IPAddress.Any, 10088); serverSocket = listener.AcceptSocket(); var childSocketThread = new Thread(() => { byte[] data = new byte[100]; serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None, ref epSender, new AsyncCallback(ReceiveData), epSender); serverSocket.Close(); }); childSocketThread.Start(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "StartListening", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.Message); } }
public void AddOrUpdate(MOE.Common.Models.MetricComment metricComment) { MOE.Common.Models.MetricComment g = (from r in db.MetricComments where r.CommentID == metricComment.CommentID select r).FirstOrDefault(); if (g != null) { try { db.Entry(g).CurrentValues.SetValues(metricComment); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.MetricCommentRepository"; error.Function = "AddOrUpdate"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } else { db.MetricComments.Add(metricComment); } }
public void AddOrUpdate(MOE.Common.Models.Approach approach) { MOE.Common.Models.Approach g = (from r in db.Approaches where r.ApproachID == approach.ApproachID select r).FirstOrDefault(); if (g != null) { try { db.Entry(g).CurrentValues.SetValues(approach); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRepository"; error.Function = "Update"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } else { try { foreach (Detector d in approach.Detectors) { if (d.DetectionTypes == null && d.DetectionTypeIDs != null) { d.DetectionTypes = db.DetectionTypes.Where(dt => d.DetectionTypeIDs.Contains(dt.DetectionTypeID)).ToList(); } } db.Approaches.Add(approach); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRepository"; error.Function = "Add"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } } }
private void CheckForLowDetectorHits(MOE.Common.Models.Signal signal) { List <MOE.Common.Models.Detector> detectors = signal.GetDetectorsForSignalThatSupportAMetric(6); //Parallel.ForEach(detectors, options, detector => foreach (MOE.Common.Models.Detector detector in detectors) { try { int channel = detector.DetChannel; string direction = detector.Approach.DirectionType.Description; DateTime start = new DateTime(); DateTime 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); } int currentVolume = detector.GetVolumeForPeriod(start, end); //Compare collected hits to low hit threshold, if (currentVolume < Convert.ToInt32(Settings.LowHitThreshold)) { MOE.Common.Models.SPMWatchDogErrorEvent error = new MOE.Common.Models.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) { MOE.Common.Models.Repositories.IApplicationEventRepository er = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); er.QuickAdd("SPMWatchDog", "Program", "CheckForLowDetectorHits", MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, detector.DetectorID + "-" + ex.Message); } } //); }
public void AddList(List <Models.SPMWatchDogErrorEvent> SPMWatchDogErrorEvents) { try { db.SPMWatchDogErrorEvents.AddRange(SPMWatchDogErrorEvents); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository er = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); er.QuickAdd("MOE.Common", "SPMWatchDogErrrorEventRepository", "AddList", MOE.Common.Models.ApplicationEvent.SeverityLevels.Medium, ex.Message); } }
public void Add(MOE.Common.Models.MetricComment metricComment) { MOE.Common.Models.MetricComment g = (from r in db.MetricComments where r.CommentID == metricComment.CommentID select r).FirstOrDefault(); if (g == null) { if (metricComment.MetricTypes == null) { metricComment.MetricTypes = db.MetricTypes .Where(x => metricComment.MetricTypeIDs.Contains(x.MetricID)).ToList(); } try { db.MetricComments.Add(metricComment); db.SaveChanges(); } catch (DbEntityValidationException e) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); string errorMessage = string.Empty; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { errorMessage += " Property:" + ve.PropertyName + " Error:" + ve.ErrorMessage; } } repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add", ApplicationEvent.SeverityLevels.Medium, errorMessage); throw new Exception(errorMessage); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); repository.QuickAdd("Moe.Common", "MetricCommentRepository", "Add", ApplicationEvent.SeverityLevels.Medium, ex.Message); throw; } } else { this.AddOrUpdate(metricComment); } }
private void Save() { try { MOE.Common.Models.SPM db = new MOE.Common.Models.SPM(); { MOE.Common.Models.Speed_Events se = new MOE.Common.Models.Speed_Events(); se.DetectorID = this.sensorId; se.timestamp = this.date; se.MPH = this.mph; se.KPH = this.kph; Regex r = new Regex("^[a-zA-Z0-9]*$"); if (r.IsMatch(se.DetectorID)) { db.Speed_Events.Add(se); db.SaveChanges(); } } } catch (DbUpdateException ex) { SqlException innerException = ex.InnerException.InnerException as SqlException; if (innerException != null && (innerException.Number == 2627 || innerException.Number == 2601)) { } else { MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException); } } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository eventRepository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); eventRepository.QuickAdd("SpeedListener", this.GetType().ToString(), "Save", MOE.Common.Models.ApplicationEvent.SeverityLevels.High, ex.HResult.ToString() + ex.Message + ex.InnerException); } }
public void Add(Models.ApproachRouteDetail newRouteDetail) { try { db.ApproachRouteDetails.Add(newRouteDetail); db.SaveChanges(); } catch (Exception ex) { MOE.Common.Models.Repositories.IApplicationEventRepository repository = MOE.Common.Models.Repositories.ApplicationEventRepositoryFactory.Create(); MOE.Common.Models.ApplicationEvent error = new ApplicationEvent(); error.ApplicationName = "MOE.Common"; error.Class = "Models.Repository.ApproachRouteDetailsRepository"; error.Function = "UpdateByRouteAndApproachID"; error.Description = ex.Message; error.SeverityLevel = ApplicationEvent.SeverityLevels.High; error.Timestamp = DateTime.Now; repository.Add(error); throw; } }