private static GTSLocationMessage getLastLocationMessageWithTrackerInfo(Trackers _tracker) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); GTSLocationMessage retVal = null; LocationMessages message; try { //try to get the Location Message that's listed as the last known if (_tracker.LastLocationId.HasValue) { message = context.LocationMessages.Where(m => m.Id == _tracker.LastLocationId.Value).First(); retVal = CreateLocationMessage(message, _tracker); } else { message = context.LocationMessages.Where(m => m.TrackerId == _tracker.Id) .OrderByDescending(x => x.ServerTime).FirstOrDefault(); if (message != null) { retVal = CreateLocationMessage(message, _tracker); //Update the Tracker object so that we know the last Location Id if (retVal != null) { UpdateTrackerInformation(retVal); } } } } catch { } return(retVal); }
public static List <LinkedTrackers> GetTrackersinDistancePublic(int distance, double?lng, double?lat, string id, int vibe) { using (GPSTrackerEntities1 context = new GPSTrackerEntities1()) { /// distnce in KM? /// Note. TrackerId is primary and TrackerId2 is secondary. LinkLevel defines how much access TrackerId2 has allowed TrackerId /// Vibe set to 0 to disable sorting by vibe ///////////////NEED TO UPDATE SOON - need to update to pass parameters properly and to cut of excess data/////////////////////// string command = @"SELECT Id, ISNull(Name,'') Name,ISNull([Description],'') [Description],LastUpdate, LastLat, LastLon, ISNull(Vibe,-1) Vibe,ISNull([Message],'') [Message],ISNull(b.[Status],-1) [Status], ISNull(( 6371 * acos( cos( radians( {0} ) ) * cos( radians( LastLat ) ) * cos( radians( LastLon ) - radians( {1} ) ) + sin( radians( {0} ) ) * sin( radians( LastLat ) ) ) ),-1) AS Distance, ISNull(datediff(hh,LastUpdate, IsNull(GETDATE(), LastUpdate)),-1) as HoursPassed, NullIf({2},Vibe) as SameVibe FROM (select * from Trackers where Status = 'LR002' and Id != '{3}') a Left Join LR_LimerInfo b On b.TrackerId = a.Id ORDER BY SameVibe ASC, HoursPassed ASC, Distance ASC"; command = String.Format(command, lat, lng, vibe, id); List <LinkedTrackers> _linked = context.ExecuteStoreQuery <LinkedTrackers>(command).ToList(); return(_linked); } }
public static List <AlertFired> GetByTrackerId(string trackerId) { var db = new GPSTrackerEntities1(); var data = db.AlertFireds.Where(x => x.TrackerId == trackerId).ToList(); return(data); }
/// <summary> /// Needs to be updated to update general tracking information /// </summary> /// <param name="?"></param> public static void UpdateTrackerInformation(LocationMessages message) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); Trackers _tracker = context.Trackers.Where(t => t.Id == message.TrackerId).FirstOrDefault(); _tracker.LastUpdate = DateTime.Now; _tracker.LastLat = (new Latitude() { Degrees = message.LatDegrees, Minutes = message.LatMinutes, Seconds = message.LatSeconds, Heading = message.LatitudeHeading[0] }).Decimal; _tracker.LastLon = (new Longitude() { Degrees = message.LngDegrees, Minutes = message.LngMinutes, Seconds = message.LngSeconds, Heading = message.LongitudeHeading[0] }).Decimal; if (message.Id != 0) { _tracker.LastLocationId = message.Id; } context.SaveChanges(); }
public static GTSLocationMessageCollection CreateGTSLocationMessages( string id, DateTime sdateTime, DateTime edateTime) { GTSLocationMessageCollection collection = new GTSLocationMessageCollection(); GPSTrackerEntities1 dbContext = new GPSTrackerEntities1(); DateTime defaultDateTime = new DateTime(1900, 01, 01); sdateTime = sdateTime == DateTime.MinValue? defaultDateTime :sdateTime; edateTime = edateTime == DateTime.MinValue? defaultDateTime:edateTime; // used >= sdateTime here so that the system will update time when tracking with the javascript // may want to implement this differently for efficiency IOrderedQueryable <LocationMessages> messages = dbContext.LocationMessages.Where(m => m.TrackerId == id && (sdateTime == defaultDateTime || m.ServerTime >= sdateTime) && (edateTime == defaultDateTime || m.ServerTime < edateTime)) .OrderBy(message => message.ServerTime); foreach (LocationMessages message in messages) { collection.Add(CreateLocationMessage(message)); } return(collection); }
public static List <GTSLocationMessageLite> GetTrackerInfoByDate( string id, DateTime sdateTime, DateTime edateTime) { List <GTSLocationMessageLite> collection = new List <GTSLocationMessageLite>(); GPSTrackerEntities1 dbContext = new GPSTrackerEntities1(); DateTime defaultDateTime = new DateTime(1900, 01, 01); sdateTime = sdateTime == DateTime.MinValue ? defaultDateTime : sdateTime; edateTime = edateTime == DateTime.MinValue ? defaultDateTime : edateTime; // used >= sdateTime here so that the system will update time when tracking with the javascript // may want to implement this differently for efficiency IOrderedQueryable <LocationMessages> messages = dbContext.LocationMessages.Where(m => m.TrackerId == id && (sdateTime == defaultDateTime || m.ServerTime >= sdateTime) && (edateTime == defaultDateTime || m.ServerTime < edateTime)) .OrderBy(message => message.ServerTime); // need to get object representing the tracker information Trackers _trackerInfo = dbContext.Trackers.Where(p => p.Id == id).First(); foreach (LocationMessages message in messages) { collection.Add(CreateLocationMessageLite(message)); } return(collection); }
public static GTSLocationMessageCollection CreateGTSLocationMessages(Guid userId) { GTSLocationMessageCollection collection = new GTSLocationMessageCollection(); GPSTrackerEntities1 dbContext = new GPSTrackerEntities1(); IQueryable <TrackerUser> trackers = dbContext.TrackerUser.Where(m => m.UserId == userId); foreach (TrackerUser _tu in trackers) { IQueryable <LocationMessages> _messages = dbContext.LocationMessages.Where(p => p.TrackerId == _tu.TrackerId); // need to get object representing the tracker information Trackers _trackerInfo = dbContext.Trackers.Where(p => p.Id == _tu.TrackerId).First(); if (_messages.Count() > 0) { DateTime _maxTime = _messages.Max(p => p.ServerTime); LocationMessages _message = _messages.Where(p => p.ServerTime == _maxTime).First(); collection.Add(CreateLocationMessage(_message, _trackerInfo)); } } return(collection); }
public static void Save(LocationMessageAlert locationMessageAlert) { var db = new GPSTrackerEntities1(); db.LocationMessageAlerts.AddObject(locationMessageAlert); db.SaveChanges(); }
public static void Save(AlertLog alertlog) { var db = new GPSTrackerEntities1(); db.AlertLogs.AddObject(alertlog); db.SaveChanges(); }
public bool UpdateVibe(int vibe, string phonenumber) { bool retval = true; GPSTrackerEntities1 context = new GPSTrackerEntities1(); // Create or overwrite LimerInfo for user LR_LimerInfo _info = context.LR_LimerInfo.Where(p => p.TrackerId == phonenumber).FirstOrDefault(); if (_info == null) { retval = false; } else { _info.Vibe = vibe; try { context.SaveChanges(); } catch (System.Exception e) { ExceptionHandler.HandleGeneralException(e); retval = false; } } return(retval); }
public static List <GeoFence> GetAll() { using (var dbContext = new GPSTrackerEntities1()) { return(dbContext.GeoFences.ToList()); } }
public bool Add(string trackerId, string mileageCount, string maintenanceNote) { try { //dirty GPSTrackerEntities1 context = new GPSTrackerEntities1(); Maintenance m = context.Maintenance.CreateObject(); m.trackerId = trackerId; m.mileage = Double.Parse(mileageCount); m.notes = maintenanceNote; m.dateTimeRecorded = DateTime.Now; // Need to update table and last set location message? Trackers _tracker = context.Trackers.Where(t => t.Id == trackerId).FirstOrDefault(); _tracker.Mileage = double.Parse(mileageCount); context.Maintenance.AddObject(m); context.SaveChanges(); return(true); } catch (System.Exception ex) { return(false); } }
public static void Save(AlertFired alertFired) { var db = new GPSTrackerEntities1(); db.AlertFireds.AddObject(alertFired); db.SaveChanges(); }
public static List <LocationMessageAlert> GetLogs(int top = 5) { var db = new GPSTrackerEntities1(); var data = db.LocationMessageAlerts.Where(x => x.IsProcessed == false).OrderBy(m => m.LocationMessageId).Take(top).ToList(); return(data); }
public static void UpdateByTrackerId(string trackerId) { var db = new GPSTrackerEntities1(); var data = db.LocationMessageAlerts.FirstOrDefault(x => x.TrackerId == trackerId && x.IsProcessed == false); data.IsProcessed = true; db.SaveChanges(); }
/// <summary> /// Checks to see if the data coming in is for an actual tracker of ours /// </summary> /// <param name="trackerId"></param> /// <returns></returns> public static bool TrackerExist(string trackerId) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); //get the Tracker (this is probably done elsewhere, so it's an extra hit, but it's less work than currently being done Trackers _tracker = context.Trackers.Where(t => t.Id == trackerId).FirstOrDefault(); return(_tracker != null); }
public static AlertFired GetActiveEnterByTrackerId(string trackerId) { var db = new GPSTrackerEntities1(); var q = from x in db.AlertFireds where x.TrackerId == trackerId && (x.Active ?? false) select x; return(q.Any() ? q.First() : null); }
public static bool IsAlreadyEnterdInFences(string trackerId) { var db = new GPSTrackerEntities1(); var q = from x in db.AlertFireds where x.TrackerId == trackerId && (x.Active ?? false) && (x.IsEnter ?? false) select x; return(q.Any()); }
public static IQueryable <TrackerCommandLog> GetTrackerCommands(string id) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); IQueryable <TrackerCommandLog> _trackerMessages = context.TrackerCommandLog.Where(t => (t.TrackerId == id) && (!t.Sent)); return(_trackerMessages); }
public static void ProcessedAlertExitFired(int id) { var db = new GPSTrackerEntities1(); var data = db.AlertFireds.FirstOrDefault(x => x.Id == id); // data.IsEnter = true; data.IsExit = true; data.Active = false; db.SaveChanges(); }
public bool CompleteRegistration(string fname, string lname, string phonenumber, string passcode) { bool retval = true; GPSTrackerEntities1 context = new GPSTrackerEntities1(); LR_Passcode pass = context.LR_Passcode.Where(p => p.phonenumber == phonenumber).FirstOrDefault(); retval = pass != null && pass.Passcode.Trim() == passcode.Trim(); if (retval) { Trackers newTracker = context.Trackers.Where(t => t.Id == phonenumber).FirstOrDefault(); // test that this works if tracker does not exist and if it does exist if (newTracker == null) { newTracker = new Trackers(); context.Trackers.AddObject(newTracker); newTracker.Id = phonenumber; } newTracker.Name = fname + " " + lname; newTracker.Type = "TYPMB"; newTracker.Status = "LR002"; // Create or overwrite LimerInfo for user LR_LimerInfo _info = context.LR_LimerInfo.Where(p => p.TrackerId == phonenumber).FirstOrDefault(); if (_info == null) { _info = new LR_LimerInfo(); context.LR_LimerInfo.AddObject(_info); _info.TrackerId = phonenumber; } _info.Vibe = 1; _info.Status = 3; _info.Message = "Hey, I'm on LimeR!!!"; try { context.SaveChanges(); } catch (System.Exception e) { ExceptionHandler.HandleGeneralException(e); retval = false; } } return(retval); }
/// <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); }
public static GTSLocationMessage GetLocationMessageById(int messageId) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); GTSLocationMessage retVal = null; LocationMessages message = context.LocationMessages.Where(t => t.Id == messageId).FirstOrDefault(); TrackerInfo info = null; if (message != null) { info = GetTrackerInfo(message.TrackerId); } retVal = CreateLocationMessage(message); retVal.TrackerDetail = info; return(retVal); }
public static bool UpdateTrackerInformation(CellLocationMessage message) { bool retval = true; GPSTrackerEntities1 context = new GPSTrackerEntities1(); Trackers _tracker = context.Trackers.Where(t => t.Id == message.TrackerID).FirstOrDefault(); _tracker.LastUpdate = DateTime.Now; _tracker.LastLat = message.Latitude.Decimal; _tracker.LastLon = message.Longitude.Decimal; context.SaveChanges(); return(retval); }
public static CellTracker GetCellTracker(string trackerId) { CellTracker tracker = null; GPSTrackerEntities1 context = new GPSTrackerEntities1(); // Need to not allow disabled statuses here Trackers _trackersDB = context.Trackers.Where(t => t.Id == trackerId).FirstOrDefault(); if (_trackersDB != null) { tracker = new CellTracker(_trackersDB.Id, _trackersDB.Name, _trackersDB.Description, _trackersDB.Status, _trackersDB.Id, _trackersDB.Password, _trackersDB.AuthorizedNumbers, _trackersDB.LastUpdate, _trackersDB.LastLat, _trackersDB.LastLon); } return(tracker); }
/// <summary> /// Needs to be updated to update general tracking information /// </summary> /// <param name="?"></param> public static void UpdateTrackerInformation(GTSLocationMessage message) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); Trackers _tracker = context.Trackers.Where(t => t.Id == message.TrackerID).FirstOrDefault(); _tracker.LastUpdate = DateTime.Now; _tracker.LastLat = message.Latitude.Decimal; _tracker.LastLon = message.Longitude.Decimal; if (message.Id != 0) { _tracker.LastLocationId = message.Id; } context.SaveChanges(); }
// Method that shares the tracker information with Security Personel Assigned // Currently First Response TODO: Update to assign response team based on location or something public static bool AlertSecurity(string trackerId) { // First response User Id 172D2D4A-8711-48EC-9ADE-D0660D4568E0 GPSTrackerEntities1 context = new GPSTrackerEntities1(); try { TrackerUser tu = TrackerUser.CreateTrackerUser(1, trackerId, new Guid("172D2D4A-8711-48EC-9ADE-D0660D4568E0"), true); context.AddToTrackerUser(tu); context.SaveChanges(); } catch (System.Exception e) { ExceptionHandler.HandleGeneralException(e); return(false); } return(true); }
public static CellTracker GetLRCellTracker(string trackerId) { LimeRCellTracker tracker = null; GPSTrackerEntities1 context = new GPSTrackerEntities1(); // Need to not allow disabled statuses here Trackers _trackersDB = context.Trackers.Where(t => t.Id == trackerId).FirstOrDefault(); LR_LimerInfo _trackersInfo = context.LR_LimerInfo.Where(t => t.TrackerId == trackerId).FirstOrDefault(); if (_trackersDB != null && _trackersDB.Status == "LR002") { tracker = new LimeRCellTracker(_trackersDB.Id, _trackersDB.Name, _trackersDB.Description, _trackersDB.Status, _trackersDB.Id, _trackersDB.Password, _trackersDB.AuthorizedNumbers, _trackersDB.LastUpdate, _trackersDB.LastLat, _trackersDB.LastLon, _trackersInfo.Vibe, _trackersInfo.Status, _trackersInfo.Message); } return(tracker); }
private static GTSLocationMessage getLastLocationMessage(string trackerId) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); GTSLocationMessage retVal = null; //get the Tracker (this is probably done elsewhere, so it's an extra hit, but it's less work than currently being done Trackers _tracker = context.Trackers.Where(t => t.Id == trackerId).FirstOrDefault(); LocationMessages message; try { //try to get the Location Message that's listed as the last known if (_tracker.LastLocationId.HasValue && _tracker.LastLocationId != 0) { message = context.LocationMessages.Where(m => m.Id == _tracker.LastLocationId.Value).First(); retVal = CreateLocationMessage(message); } else { message = context.LocationMessages.Where(m => m.TrackerId == trackerId) .OrderByDescending(x => x.ServerTime).FirstOrDefault(); if (message != null) { retVal = CreateLocationMessage(message); //Update the Tracker object so that we know the last Location Id if (retVal != null) { UpdateTrackerInformation(retVal); } } } } catch { } return(retVal); }
public static GPSTrackerOutput GetTrackerOutput(string id, int number) { GPSTrackerEntities1 context = new GPSTrackerEntities1(); IQueryable <TrackerOutput> _trackerOutputs = context.TrackerOutputs.Where(t => (t.TrackerId == id) && (t.Number == number)); //If it's not in the DB, we'll generate an object that basically says 'leave everything as it is'. Code higher up will know //that we shouldn't even send commands for this. if ((_trackerOutputs == null) || (_trackerOutputs.Count() == 0)) { return(new GPSTrackerOutput(id, number, OutputState.Previous, OutputState.Previous, OutputTriggerType.Immediate)); } TrackerOutput _output = _trackerOutputs.First(); return(new GPSTrackerOutput( id, number, _output.ProposedState == 1 ? OutputState.On:_output.ProposedState == 2 ? OutputState.Off:OutputState.Previous, _output.LastVerifiedState == 1 ? OutputState.On : _output.LastVerifiedState == 2 ? OutputState.Off : OutputState.Previous, _output.TriggerType == 1 ? OutputTriggerType.Immediate : _output.TriggerType == 2 ? OutputTriggerType.TenK : OutputTriggerType.TwentyK)); }