public Controller_Event_Log GetFirstEventBeforeDateByEventCodeAndParameter(string signalId, int eventCode, int eventParam, DateTime date)
 {
     try
     {
         DateTime tempDate  = date.AddDays(-1);
         var      lastEvent = _db.Controller_Event_Log.Where(c => c.SignalID == signalId &&
                                                             c.Timestamp >= tempDate &&
                                                             c.Timestamp < date &&
                                                             c.EventCode == eventCode &&
                                                             c.EventParam == eventParam)
                              .OrderByDescending(c => c.Timestamp).FirstOrDefault();
         return(lastEvent);
     }
     catch (Exception ex)
     {
         IApplicationEventRepository logRepository = ApplicationEventRepositoryFactory.Create();
         ApplicationEvent            e             = new ApplicationEvent();
         e.ApplicationName = "MOE.Common";
         e.Class           = GetType().ToString();
         e.Function        = "GetEventsByEventCodesParamWithOffsetAndLatencyCorrection";
         e.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
         e.Description     = ex.Message;
         e.Timestamp       = DateTime.Now;
         logRepository.Add(e);
         return(null);
     }
 }
 public List <Controller_Event_Log> GetEventsByEventCodesParamWithOffsetAndLatencyCorrection(string signalId,
                                                                                             DateTime startTime, DateTime endTime, List <int> eventCodes, int param, double offset, double latencyCorrection)
 {
     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);
             cel.Timestamp = cel.Timestamp.AddSeconds(0 - latencyCorrection);
         }
         return(events);
     }
     catch (Exception ex)
     {
         IApplicationEventRepository logRepository =
             ApplicationEventRepositoryFactory.Create();
         ApplicationEvent e = new ApplicationEvent();
         e.ApplicationName = "MOE.Common";
         e.Class           = GetType().ToString();
         e.Function        = "GetEventsByEventCodesParamWithOffsetAndLatencyCorrection";
         e.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
         e.Timestamp       = DateTime.Now;
         e.Description     = ex.Message;
         logRepository.Add(e);
         throw;
     }
 }
 public List <Controller_Event_Log> GetSignalEventsByEventCodes(string signalId,
                                                                DateTime startTime, DateTime endTime, List <int> eventCodes)
 {
     try
     {
         var events = (from s in _db.Controller_Event_Log
                       where s.SignalID == signalId &&
                       s.Timestamp >= startTime &&
                       s.Timestamp <= endTime &&
                       eventCodes.Contains(s.EventCode)
                       select s).ToList();
         events.Sort((x, y) => DateTime.Compare(x.Timestamp, y.Timestamp));
         return(events);
     }
     catch (Exception ex)
     {
         IApplicationEventRepository logRepository =
             ApplicationEventRepositoryFactory.Create();
         ApplicationEvent e = new ApplicationEvent();
         e.ApplicationName = "MOE.Common";
         e.Class           = GetType().ToString();
         e.Function        = "GetSignalEventsByEventCodes";
         e.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
         e.Timestamp       = DateTime.Now;
         e.Description     = ex.Message;
         logRepository.Add(e);
         throw;
     }
 }
 public List <Controller_Event_Log> GetSignalEventsByEventCode(string signalId,
                                                               DateTime startTime, DateTime endTime, int eventCode)
 {
     try
     {
         return((from r in _db.Controller_Event_Log
                 where r.SignalID == signalId &&
                 r.Timestamp >= startTime &&
                 r.Timestamp < endTime &&
                 r.EventCode == eventCode
                 select r).ToList());
     }
     catch (Exception ex)
     {
         IApplicationEventRepository logRepository =
             ApplicationEventRepositoryFactory.Create();
         ApplicationEvent e = new ApplicationEvent();
         e.ApplicationName = "MOE.Common";
         e.Class           = GetType().ToString();
         e.Function        = "GetSignalEventsByEventCode";
         e.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
         e.Timestamp       = DateTime.Now;
         e.Description     = ex.Message;
         logRepository.Add(e);
         throw;
     }
 }
        public List <Controller_Event_Log> GetTopNumberOfSignalEventsBetweenDates(string signalId, int numberOfRecords,
                                                                                  DateTime startTime, DateTime endTime)
        {
            try
            {
                List <Controller_Event_Log> events =
                    (from r in _db.Controller_Event_Log
                     where r.SignalID == signalId &&
                     r.Timestamp >= startTime &&
                     r.Timestamp < endTime
                     select r).Take(numberOfRecords).ToList();

                if (events != null)
                {
                    return(events);
                }
                List <Controller_Event_Log> emptyEvents = new List <Controller_Event_Log>();
                return(emptyEvents);
            }
            catch (Exception ex)
            {
                IApplicationEventRepository logRepository =
                    ApplicationEventRepositoryFactory.Create();
                ApplicationEvent e = new ApplicationEvent();
                e.ApplicationName = "MOE.Common";
                e.Class           = GetType().ToString();
                e.Function        = "GetTopNumberOfSignalEventsBetweenDates";
                e.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
                e.Timestamp       = DateTime.Now;
                e.Description     = ex.Message;
                logRepository.Add(e);
                throw;
            }
        }
 public int GetEventCountByEventCodesParamDateTimeRange(string signalId,
                                                        DateTime startTime, DateTime endTime, int startHour, int startMinute, int endHour, int endMinute,
                                                        List <int> eventCodes, int param)
 {
     try
     {
         return
             ((from s in _db.Controller_Event_Log
               where s.SignalID == signalId &&
               s.Timestamp >= startTime &&
               s.Timestamp <= endTime &&
               ((s.Timestamp.Hour > startHour && s.Timestamp.Hour < endHour) ||
                (s.Timestamp.Hour == startHour && s.Timestamp.Hour == endHour &&
                 s.Timestamp.Minute >= startMinute && s.Timestamp.Minute <= endMinute) ||
                (s.Timestamp.Hour == startHour && s.Timestamp.Hour < endHour && s.Timestamp.Minute >= startMinute) ||
                (s.Timestamp.Hour < startHour && s.Timestamp.Hour == endHour && s.Timestamp.Minute <= endMinute))
               &&
               s.EventParam == param &&
               eventCodes.Contains(s.EventCode)
               select s).Count());
     }
     catch (Exception ex)
     {
         IApplicationEventRepository logRepository =
             ApplicationEventRepositoryFactory.Create();
         ApplicationEvent e = new ApplicationEvent();
         e.ApplicationName = "MOE.Common";
         e.Class           = GetType().ToString();
         e.Function        = "GetEventCountByEventCodesParamDateTimeRange";
         e.SeverityLevel   = ApplicationEvent.SeverityLevels.High;
         e.Timestamp       = DateTime.Now;
         e.Description     = ex.Message;
         logRepository.Add(e);
         throw;
     }
 }