Esempio 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();
        }
Esempio 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();
        }
Esempio n. 3
0
 internal bool ServesLine(TransitLine line)
 {
     return StopName == line.StopName && Direction == line.Direction;
 }
Esempio 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();
        }
 internal bool ServesLine(TransitLine line)
 {
     return(StopName == line.StopName && Direction == line.Direction);
 }