Пример #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();
        }
Пример #2
0
        /// <summary>
        /// The first time a viewmodel is hooked up to the model,
        /// populate the Lines collection with lines from the model
        /// </summary>
        private void updateLines()
        {
            var newStops = new ObservableCollection <TransitStopViewModel>();

            foreach (var line in model.Lines)
            {
                var matchingStop = newStops.FirstOrDefault(s => s.ServesLine(line));
                if (matchingStop == null)
                {
                    matchingStop = new TransitStopViewModel()
                    {
                        StopName  = line.StopName,
                        Direction = line.Direction,
                        Arrivals  = new ObservableCollection <ArrivalViewModel>(),
                    };
                    newStops.Add(matchingStop);
                }
                updateLine(line, matchingStop);
            }
            Stops = new ObservableCollection <TransitStopViewModel>(newStops.OrderBy(s => s.Direction).OrderBy(s => s.StopName));
            updateTimestamp();
        }
Пример #3
0
 /// <summary>
 /// The first time a viewmodel is hooked up to the model,
 /// populate the Lines collection with lines from the model
 /// </summary>
 private void updateLines()
 {
     var newStops = new ObservableCollection<TransitStopViewModel>();
     foreach (var line in model.Lines)
     {
         var matchingStop = newStops.FirstOrDefault(s => s.ServesLine(line));
         if (matchingStop == null)
         {
             matchingStop = new TransitStopViewModel()
             {
                 StopName = line.StopName,
                 Direction = line.Direction,
                 Arrivals = new ObservableCollection<ArrivalViewModel>(),
             };
             newStops.Add(matchingStop);
         }
         updateLine(line, matchingStop);
     }
     Stops = new ObservableCollection<TransitStopViewModel>(newStops.OrderBy(s => s.Direction).OrderBy(s => s.StopName));
     updateTimestamp();
 }
Пример #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();
        }