Ejemplo n.º 1
0
        private void updateLine(TransitLine updatedLine, TransitStopViewModel stopToUpdate = null)
        {
            if (stopToUpdate == null)
            {
                stopToUpdate = Stops.Single(stop => stop.Direction == updatedLine.Direction && stop.StopName == updatedLine.StopName);
            }

            // Remove arrivals that are not there in the model
            // .ToList() makes a copy of the collection to iterate over
            foreach (var existingArrival in stopToUpdate.Arrivals.Where(a => a.RouteName == updatedLine.RouteName).ToList())
            {
                if (!updatedLine.Arrivals.Contains(existingArrival.ArrivalTime))
                {
                    stopToUpdate.Arrivals.Remove(existingArrival);
                }
            }
            // Add arrivals that are not there in the viewmodel
            foreach (var arrivalInModel in updatedLine.Arrivals)
            {
                if (!stopToUpdate.Arrivals.Any(a => a.RouteName == updatedLine.RouteName && a.ArrivalTime == arrivalInModel))
                {
                    var newArrival = getNewArrival(updatedLine.RouteName, arrivalInModel, updatedLine.WalkTime);
                    if (newArrival.WhenINeedToLeave < BUS_CUTOFF)
                    {
                        continue;
                    }
                    var insertionPoint = stopToUpdate.Arrivals.Count(a => a.ArrivalTime < arrivalInModel);
                    stopToUpdate.Arrivals.Insert(insertionPoint, newArrival);
                }
            }

            updateTimestamp();
        }
Ejemplo n.º 2
0
        private void updateLine(TransitLine updatedLine, TransitLineViewModel lineToUpdate = null)
        {
            if (lineToUpdate == null)
                lineToUpdate = Lines.Single(line => line.Equals(updatedLine));

            // Remove arrivals that are not there in the model
            // .ToList() makes a copy of the collection to iterate over
            foreach (var existingArrival in lineToUpdate.Arrivals.ToList())
            {
                if (!updatedLine.Arrivals.Contains(existingArrival.ArrivalTime))
                {
                    lineToUpdate.Arrivals.Remove(existingArrival);
                }
            }
            // Add arrivals that are not there in the viewmodel
            foreach (var arrivalInModel in updatedLine.Arrivals)
            {
                if (!lineToUpdate.Arrivals.Any(a => a.ArrivalTime == arrivalInModel))
                {
                    var newArrival = getNewArrival(arrivalInModel, updatedLine.WalkTime);
                    if (newArrival.WhenINeedToLeave < BUS_CUTOFF)
                    {
                        continue;
                    }
                    var insertionPoint = lineToUpdate.Arrivals.Count(a => a.ArrivalTime < arrivalInModel);
                    lineToUpdate.Arrivals.Insert(insertionPoint, newArrival);
                }
            }

            updateTimestamp();
        }
Ejemplo n.º 3
0
 internal bool ServesLine(TransitLine line)
 {
     return StopName == line.StopName && Direction == line.Direction;
 }
Ejemplo n.º 4
0
        private void updateLine(TransitLine updatedLine, TransitStopViewModel stopToUpdate = null)
        {
            if (stopToUpdate == null)
                stopToUpdate = Stops.Single(stop => stop.Direction == updatedLine.Direction && stop.StopName == updatedLine.StopName);

            // Remove arrivals that are not there in the model
            // .ToList() makes a copy of the collection to iterate over
            foreach (var existingArrival in stopToUpdate.Arrivals.Where(a => a.RouteName == updatedLine.RouteName).ToList())
            {
                if (!updatedLine.Arrivals.Contains(existingArrival.ArrivalTime))
                {
                    stopToUpdate.Arrivals.Remove(existingArrival);
                }
            }
            // Add arrivals that are not there in the viewmodel
            foreach (var arrivalInModel in updatedLine.Arrivals)
            {
                if (!stopToUpdate.Arrivals.Any(a => a.RouteName == updatedLine.RouteName && a.ArrivalTime == arrivalInModel))
                {
                    var newArrival = getNewArrival(updatedLine.RouteName, arrivalInModel, updatedLine.WalkTime);
                    if (newArrival.WhenINeedToLeave < BUS_CUTOFF)
                    {
                        continue;
                    }
                    var insertionPoint = stopToUpdate.Arrivals.Count(a => a.ArrivalTime < arrivalInModel);
                    stopToUpdate.Arrivals.Insert(insertionPoint, newArrival);
                }
            }

            updateTimestamp();
        }
Ejemplo n.º 5
0
 internal bool ServesLine(TransitLine line)
 {
     return(StopName == line.StopName && Direction == line.Direction);
 }