/// <summary> /// Factory Method for Events /// </summary> /// <param name="eventId"></param> /// <returns></returns> public GTSBizObjects.Events.TrackerEvents.TrackerEvent GetEvent(int eventId) { GPSTrackerEntities1 dbContext = new GPSTrackerEntities1(); GTSDataStorage.Event theEvent = dbContext.Events.Where(t => t.Id == eventId).FirstOrDefault(); Events.TrackerEvents.TrackerEvent retEvent; switch (theEvent.Type) { // Should find a better, more configurable way to get names for Inputs - TODO // Configurable by client and probably type, including tempat for description // TODO - Exception Handling case 1: retEvent = new TrackerEvents.Speeding(theEvent); break; case 2: retEvent = new TrackerEvents.ExcessiveIdling(theEvent); break; //case 3: retEvent = new TrackerEvents.EngineCutOn(theEvent); break; //case 4: retEvent = new TrackerEvents.EngineCutOff(theEvent); break; //case 5: retEvent = new TrackerEvents.EnterLocation(theEvent); break; //case 6: retEvent = new TrackerEvents.ExitLocation(theEvent); break; case 7: retEvent = new TrackerEvents.ExternalPowerCut(theEvent); break; case 8: retEvent = new TrackerEvents.GPSBlindAreaEntered(theEvent); break; case 9: retEvent = new TrackerEvents.GPSBlindAreaExited(theEvent); break; case 10: retEvent = new TrackerEvents.LowBattery(theEvent); break; case 11: retEvent = new TrackerEvents.TrackerTurnedOn(theEvent); break; case 12: retEvent = new TrackerEvents.GPSAntennaCut(theEvent); break; case 13: retEvent = new TrackerEvents.InputActive(theEvent); break; case 14: retEvent = new TrackerEvents.InputInactive(theEvent); break; case 15: retEvent = new TrackerEvents.InputActive(theEvent); break; case 16: retEvent = new TrackerEvents.InputInactive(theEvent); break; default: retEvent = new TrackerEvents.TrackerAlarm(theEvent); break; } return(retEvent); }
private Event createSpeedingEvent(GTSLocationMessage locationMessage, GTSLocationMessage prevMessage) { // get speeding number from config for client/tracker int speedTresh = 80; // Need to pull this from config for multiple clients TODO Events.TrackerEvents.Speeding speed; // Check for speeding on both location messages if (locationMessage.Speed > speedTresh) { // If speeding is a contiuation - find event that links to prev location message that is speeding and modify if (prevMessage.Speed > speedTresh) { // Pull event relating to previous message GTSDataStorage.Event theEvent = context.Events.Where(e => e.ObjectId == locationMessage.TrackerID). OrderByDescending(i => i.Time).FirstOrDefault(); if (theEvent == null) { speed = new TrackerEvents.Speeding(); } else { speed = new TrackerEvents.Speeding(theEvent); } } else { // create new event if event now starts speed = new TrackerEvents.Speeding(); } speed.AddLocationMessage(locationMessage); } else { return(null); } return(speed); // return the modified event }