Exemplo n.º 1
0
        private Event createIdleEvent(GTSLocationMessage locationMessage, GTSLocationMessage prevMessage)
        {
            int idleTresh = 15; // get idle number form config for client/tracker

            Events.TrackerEvents.ExcessiveIdling idleEvent;
            // && prevMessage.DInput5 == true
            if (new TimeSpan(prevMessage.IdleTime).TotalMinutes >= idleTresh && prevMessage.DInput5 == true)
            {
                // TODO migh be a better way to select this using Linq to xml
                //Update or create new event
                GTSDataStorage.Event eventT = context.Events.Where(e => e.ObjectId == prevMessage.TrackerID).
                                              Where(e => e.Time == prevMessage.ClientRecordedDateTime).FirstOrDefault();

                if (eventT != null)
                {
                    // update the event
                    idleEvent = new TrackerEvents.ExcessiveIdling(eventT);
                    idleEvent.AddLocationMessage(locationMessage);
                }
                else
                {
                    // create a new one
                    idleEvent = new TrackerEvents.ExcessiveIdling();
                    idleEvent.AddLocationMessage(prevMessage, locationMessage);
                }

                return(idleEvent);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public ExcessiveIdling(GTSDataStorage.Event eventT) : base(eventT)
        {
            if (eventT.ExtendedProperties != null)
            {
                XDocument doc = XDocument.Parse(eventT.ExtendedProperties);

                XElement ids = doc.Descendants("LocationMessagesID").FirstOrDefault();
                if (ids != null)
                {
                    _locMsgID = int.Parse(ids.Value);
                }
                _locationMessage = GTSBizObjects.Management.GetLocationMessageById(_locMsgID);

                XElement endTime = doc.Descendants("EndTime").FirstOrDefault();
                if (endTime != null)
                {
                    _endTime = XmlConvert.ToDateTime(endTime.Value);
                }

                XElement idleTime = doc.Descendants("IdleTime").FirstOrDefault();
                if (idleTime != null)
                {
                    _idleTime = long.Parse(idleTime.Value);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Accepts a location message to point to for further details
        /// </summary>
        public void AddLocationMessage(GTSLocationMessage locationMessage)
        {
            if (_messages.Count == 0)
            {
                SetTrackerInfo(locationMessage);
            }
            _messages.Add(locationMessage);


            // Probably will need to do a reverse lookup here!!! TODO
            GTSLocationMessage theFirst = _messages.First();

            _location = theFirst.LatitudeDecimal + " " + theFirst.LongitudeDecimal; // Don't know if this gives correct stuff - need to check on Heading

            if (_messages.Count == 1)
            {
                Time = _startTime = locationMessage.ClientRecordedDateTime;
            }
            _endTime = locationMessage.ClientRecordedDateTime;

            if (locationMessage.Speed > _maxSpeed)
            {
                _maxSpeed     = Convert.ToInt32(locationMessage.Speed);
                _maxSpeedTime = locationMessage.ClientRecordedDateTime;
            }
            this.generateEventDescription();
        }
Exemplo n.º 4
0
 public void AddLocationMessage(GTSLocationMessage prevmsg, GTSLocationMessage msg)
 {
     base.SetTrackerInfo(msg);
     Time             = prevmsg.ClientRecordedDateTime;
     _endTime         = msg.ClientRecordedDateTime;
     _idleTime        = prevmsg.IdleTime;
     _locationMessage = prevmsg;
     _locMsgID        = _locationMessage.Id;
 }
Exemplo n.º 5
0
        public void SetTrackerInfo(GTSLocationMessage theMsg)
        {
            TrackerInfo tracker = theMsg.TrackerDetail;

            _locationMessage   = theMsg;
            _locationMessageId = theMsg.Id;
            _tracker           = tracker;
            _trackerName       = _tracker.Name;
            _objectid          = tracker.Id;
        }
Exemplo n.º 6
0
 public void AddLocationMessage(GTSLocationMessage msg, GeoFence geoFence)
 {
     base.SetTrackerInfo(msg);
     Time             = msg.ClientRecordedDateTime;
     _entryTime       = msg.ClientRecordedDateTime;
     _locationMessage = msg;
     _locMsgID        = _locationMessage.Id;
     _geoFence        = geoFence;
     _geoFenceId      = geoFence.Id;
 }
Exemplo n.º 7
0
        public Speeding(GTSDataStorage.Event eventt) : base(eventt)
        {// TODO - Stuff needs to go in try catch and try parse and use exception handler
            _messages = new List <GTSLocationMessage>();

            if (eventt.ExtendedProperties != null)
            {
                XDocument doc = XDocument.Parse(eventt.ExtendedProperties);
                XElement  ids = doc.Descendants("LocationMessages").FirstOrDefault();
                foreach (XElement n in ids.Descendants("ID"))
                {
                    GTSLocationMessage msg = GTSBizObjects.Management.GetLocationMessageById(int.Parse(n.Value));
                    // if (_messages.Count == 0) SetTrackerInfo(msg);
                    if (msg != null)
                    {
                        _messages.Add(msg);
                    }
                }


                XElement maxSpeed = doc.Descendants("MaxSpeed").FirstOrDefault();
                if (maxSpeed != null)
                {
                    _maxSpeed = int.Parse(maxSpeed.Value);
                }

                XElement speedStart = doc.Descendants("SpeedStartTime").FirstOrDefault();
                if (speedStart != null)
                {
                    _startTime = XmlConvert.ToDateTime(speedStart.Value);
                }

                XElement speedEnd = doc.Descendants("SpeedEndTime").FirstOrDefault();
                if (speedEnd != null)
                {
                    _endTime = XmlConvert.ToDateTime(speedEnd.Value);
                }

                XElement speedLoc = doc.Descendants("SpeedLocation").FirstOrDefault();
                if (speedLoc != null)
                {
                    _location = speedLoc.Value;
                }

                XElement maxSpeedTime = doc.Descendants("MaxDateTime").FirstOrDefault();
                if (maxSpeedTime != null)
                {
                    _maxSpeedTime = XmlConvert.ToDateTime(maxSpeedTime.Value);
                }
            }
        }
Exemplo n.º 8
0
 public TrackerEvent(GTSDataStorage.Event eventt) : base(eventt)
 {
     if (eventt.ExtendedProperties != null)
     {
         XDocument doc  = XDocument.Parse(eventt.ExtendedProperties);
         XElement  name = doc.Descendants("TrackerName").FirstOrDefault();
         if (name != null)
         {
             _trackerName = name.Value;
         }
         XElement locmsg = doc.Descendants("LocationMessageID").FirstOrDefault();
         if (locmsg != null)
         {
             int.TryParse(locmsg.Value, out _locationMessageId);
             this._locationMessage = GTSBizObjects.Management.GetLocationMessageById(_locationMessageId);
             this._tracker         = _locationMessage.TrackerDetail;
         }
     }
 }
Exemplo n.º 9
0
        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
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets the list of events from a location Message analysis for the vt310e
        /// </summary>
        /// <returns></returns>
        public List <Event> GetVT310eEvents(GTSLocationMessage locationMessage, GTSLocationMessage prevMessage)
        {
            List <Event> events = new List <Event>();


            // should link geofence checking in here

            // Need to check all known events
            // Currently we have no case where an event can point to more than one event at a time - this may change when geo fencing is put in!!!! TODO
            // Wondering If there should be a separation of events by a level of priority for reporting here or in the DB? In the DB


            if (prevMessage != null && locationMessage.Id == 0)
            {
                locationMessage.Id = prevMessage.Id;
            }

            Event theEvent;

            if (locationMessage.Speed > 0)
            {
                theEvent = createSpeedingEvent(locationMessage, prevMessage);
                if (theEvent != null)
                {
                    events.Add(theEvent);
                }
            }
            else
            {
                theEvent = createIdleEvent(locationMessage, prevMessage);
                if (theEvent != null)
                {
                    events.Add(theEvent);
                }
            }

            // Get Alarms
            if (locationMessage.GetType() == (typeof(VT310eAlarmLocationMessage)))
            {
                VT310eAlarmLocationMessage msg = (VT310eAlarmLocationMessage)locationMessage;
                // tests for different alarm types
                switch (msg.AlarmID)
                {
                // Should find a better, more configurable way to get names for Inputs - TODO
                // Configurable by client and probably type, including tempat for description

                case "01": theEvent = new TrackerEvents.InputActive(msg, 1, "SOS Button"); break;

                case "02": theEvent = new TrackerEvents.InputActive(msg, 2); break;

                case "03": theEvent = new TrackerEvents.InputActive(msg, 3); break;

                case "04": theEvent = new TrackerEvents.InputActive(msg, 4); break;

                case "05": theEvent = new TrackerEvents.InputActive(msg, 5, "Engine"); break;

                case "10": theEvent = new TrackerEvents.LowBattery(msg); break;

                case "14": theEvent = new TrackerEvents.TrackerTurnedOn(msg); break;

                case "15": theEvent = new TrackerEvents.GPSBlindAreaEntered(msg); break;

                case "16": theEvent = new TrackerEvents.GPSBlindAreaExited(msg); break;

                case "31": theEvent = new TrackerEvents.InputInactive(msg, 1, "SOS Button"); break;

                case "32": theEvent = new TrackerEvents.InputInactive(msg, 2); break;

                case "33": theEvent = new TrackerEvents.InputInactive(msg, 3); break;

                case "34": theEvent = new TrackerEvents.InputInactive(msg, 4); break;

                case "35": theEvent = new TrackerEvents.InputInactive(msg, 5, "Engine"); break;

                case "50": theEvent = new TrackerEvents.ExternalPowerCut(msg); break;

                case "53": theEvent = new TrackerEvents.GPSAntennaCut(msg); break;

                default: theEvent = new TrackerEvents.TrackerAlarm(msg); break;
                }
                if (theEvent != null)
                {
                    events.Add(theEvent);
                }
            }

            List <Event> entryExitEvents = new List <Event>();

            try
            {
                entryExitEvents = retrieveGeoFenceEventList(locationMessage, prevMessage);
            }
            catch (System.Exception ex)
            {
            }

            foreach (Event item in entryExitEvents)
            {
                events.Add(item);
            }

            return(events);
        }
Exemplo n.º 11
0
        private static List <Event> retrieveGeoFenceEventList(GTSLocationMessage locationMessage, GTSLocationMessage prevMessage)
        {
            List <Event> geoFenceEvents = new List <Event>();

            // Get User Logged in
            // For now we'll just get all associated with user
            // TODO - Need to update this to pull form User/Account and tracker level later on
            // TODO - implemented using the "Created User" on the table, should be done with a proper mapping table

            if (locationMessage.TrackerID != null)
            {
                //get list of GeoFences for tracker
                List <GTSDataStorage.GeoFence> geoFencesFromDatabase = GTSDataStorage.Manager.FencesManager.GetFencesByTrackerId(locationMessage.TrackerID);
                List <GTSBizObjects.GeoFence>  geoFences             = new List <GeoFence>();


                // Why are these two for loops separate? TODO
                foreach (GTSDataStorage.GeoFence item in geoFencesFromDatabase)
                {
                    GTSBizObjects.GeoFence geoFence = new GeoFence(item.FencesId, item.FencesName, item.FencesCoordinate, item.IsPublic, item.Details, item.Status, item.Zoom, item.CreatedBy, item.CreatedDate, item.UpdatedBy, item.UpdatedDate);
                    geoFences.Add(geoFence);
                }
                foreach (GTSBizObjects.GeoFence item in geoFences)
                {
                    // Check if prev message and current message are in the geofence

                    // TODO: Using the model of speed event we can track how long a vehicle spent in a geo fence and what they did there
                    // If prev message and message are in the geo fence we simply update the last geo fence event tied with location message and time
                    // Stored in extended properties for the event.

                    try {
                        List <Location> locations = Events.Hepler.GeoFenceLocations(item.Coordinates);

                        bool prevLocationInFence = Events.Hepler.IsPointInPolygon(locations, new Location {
                            Lt = (double)prevMessage.LatitudeDecimal, Lg = (double)prevMessage.LongitudeDecimal
                        });
                        bool currentLocationInFence = Events.Hepler.IsPointInPolygon(locations, new Location {
                            Lt = (double)locationMessage.LatitudeDecimal, Lg = (double)locationMessage.LongitudeDecimal
                        });

                        //if tracker entered a Geo Fence add to list of events
                        if (!prevLocationInFence && currentLocationInFence)
                        {
                            Events.TrackerEvents.EnterLocation enterLocationEvent = new EnterLocation();
                            enterLocationEvent.AddLocationMessage(locationMessage, item);
                            geoFenceEvents.Add(enterLocationEvent);
                        }

                        //if tracker exited a Geo Fence add to list of events
                        if (prevLocationInFence && !currentLocationInFence)
                        {
                            Events.TrackerEvents.ExitLocation exitLocationEvent = new ExitLocation();
                            exitLocationEvent.AddLocationMessage(locationMessage, item);
                            geoFenceEvents.Add(exitLocationEvent);
                        }
                    }catch (System.Exception e)
                    {
                        Utilities.writeLine("Debug !: A GeoFence may be corrupted!!! " + e.Message);
                    }
                }
            }

            return(geoFenceEvents);
        }
Exemplo n.º 12
0
 public void AddLocationMessage(GTSLocationMessage msg)
 {
     _endTime  = msg.ClientRecordedDateTime;
     _idleTime = msg.IdleTime;
 }