コード例 #1
0
ファイル: TransitViewModel.cs プロジェクト: clemensul/Mirror
        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();
        }
コード例 #2
0
ファイル: TransitViewModel.cs プロジェクト: clemensul/Mirror
 /// <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 newLines = new ObservableCollection<TransitLineViewModel>();
     foreach (var line in model.Lines)
     {
         var newLineViewModel = new TransitLineViewModel()
         {
             RouteName = line.RouteName,
             StopName = line.StopName,
             Arrivals = new ObservableCollection<ArrivalViewModel>(),
         };
         updateLine(line, newLineViewModel);
         newLines.Add(newLineViewModel);
     }
     Lines = newLines;
     updateTimestamp();
 }