示例#1
0
        private void Setup17MinBus3MinWait20MinBus_Probe4MinAwayAt1MinToSpare(Traveler tr, List <Step> steps)
        {
            //Override times to make trip present tense
            //inbound step
            steps[0].StartDate = DateTime.UtcNow.AddMinutes(-20);
            steps[0].EndDate   = DateTime.UtcNow.AddMinutes(-3);
            //walk step
            steps.RemoveAt(1);
            //tconnect step
            steps[1].StartDate  = DateTime.UtcNow;
            steps[1].EndDate    = DateTime.UtcNow.AddMinutes(30);
            steps[1].StepNumber = 2;

            DateTime probetimestamp = DateTime.UtcNow.AddMinutes(-2).AddSeconds(30);
            //Set up a probe snapshot coming from the James Rd Gate
            //It takes 4:01 minutes to travel between gates.
            ProbeSnapshotEntry newProbeSnapshot = new ProbeSnapshotEntry
            {
                PartitionKey = tr.LastName,//inbound vehicle name is last name of traveler
                RowKey       = Guid.NewGuid().ToString(),

                PositionTimestamp = probetimestamp,
                Accuracy          = 5,
                Altitude          = 123,
                Heading           = 180,
                Latitude          = 39.977592,
                Longitude         = -82.913054,
                Satellites        = 0,
                Speed             = 14.77999305725097
            };

            _probeTable.AddEntity(newProbeSnapshot);
        }
示例#2
0
        /// <summary>
        /// Receives ProbeVehicleData by inbound vehicle for the latest vehicle location and saves it to the cloud.
        /// </summary>
        /// <param name="probeDataMessage"></param>
        /// <returns></returns>
        public HttpResponseMessage PostProbeData(ProbeVehicleData probeDataMessage)
        {
            try
            {
                if (String.IsNullOrEmpty(probeDataMessage.InboundVehicle))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "InboundVehicle cannot be null or empty"));
                }

                // Convert from Java timestamp
                DateTime dtTemp = new DateTime(1970, 1, 1, 0, 0, 0);

                DateTime           newestProbeTimestamp = dtTemp;
                ProbeSnapshotEntry newestProbeSnapshot  = null;

                foreach (PositionSnapshot positionSnapshot in probeDataMessage.Positions)
                {
                    DateTime lastUpdatedDate = dtTemp.AddMilliseconds(positionSnapshot.TimeStamp);

                    ProbeSnapshotEntry newProbeSnapshot = new ProbeSnapshotEntry
                    {
                        PartitionKey      = probeDataMessage.InboundVehicle,
                        RowKey            = Guid.NewGuid().ToString(),
                        Latitude          = positionSnapshot.Latitude,
                        Longitude         = positionSnapshot.Longitude,
                        Speed             = positionSnapshot.Speed,
                        Heading           = positionSnapshot.Heading,
                        PositionTimestamp = lastUpdatedDate,
                        Satellites        = positionSnapshot.Satellites,
                        Accuracy          = positionSnapshot.Accuracy,
                        Altitude          = positionSnapshot.Altitude
                    };

                    _probeTable.AddEntity(newProbeSnapshot);

                    //Check for and hang on to most recent probe snapshot
                    if (lastUpdatedDate > newestProbeTimestamp)
                    {
                        newestProbeTimestamp = lastUpdatedDate;
                        newestProbeSnapshot  = newProbeSnapshot;
                    }
                }

                SaveNewestProbeSnapshot(newestProbeSnapshot);

                return(Request.CreateResponse(HttpStatusCode.NoContent));
            }
            catch (Exception ex)
            {
                string msg = RecordException(ex, "ProbeController.PostProbeData");
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message + msg));
            }
        }
示例#3
0
        private void SaveNewestProbeSnapshot(ProbeSnapshotEntry newestProbeSnapshot)
        {
            if (newestProbeSnapshot == null)
            {
                return;
            }

            //Find existing vehicle record
            LastVehiclePosition currentVehicle = Uow.Repository <LastVehiclePosition>().Query().Get().FirstOrDefault(v => v.VehicleName == newestProbeSnapshot.PartitionKey);

            if (currentVehicle != null)
            {
                //Update vehicles last position values
                currentVehicle.PositionTimestamp = newestProbeSnapshot.PositionTimestamp;
                currentVehicle.Latitude          = newestProbeSnapshot.Latitude;
                currentVehicle.Longitude         = newestProbeSnapshot.Longitude;
                currentVehicle.Speed             = newestProbeSnapshot.Speed;
                currentVehicle.Heading           = (short)newestProbeSnapshot.Heading;
                currentVehicle.Accuracy          = newestProbeSnapshot.Accuracy;

                Uow.Repository <LastVehiclePosition>().Update(currentVehicle);
            }
            else
            {
                LastVehiclePosition lvp = new LastVehiclePosition
                {
                    VehicleName       = newestProbeSnapshot.PartitionKey,
                    PositionTimestamp = newestProbeSnapshot.PositionTimestamp,
                    Latitude          = newestProbeSnapshot.Latitude,
                    Longitude         = newestProbeSnapshot.Longitude,
                    Speed             = newestProbeSnapshot.Speed,
                    Heading           = (short)newestProbeSnapshot.Heading,
                    Accuracy          = newestProbeSnapshot.Accuracy
                };

                Uow.Repository <LastVehiclePosition>().Insert(lvp);
            }

            Uow.Save();
        }