private void ArrivalsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (e.AddedItems.Count != 0)
     {
         ArrivalAndDeparture arrival = (ArrivalAndDeparture)e.AddedItems[0];
         viewModel.SwitchToRouteByArrival(arrival, () => UpdateAppBar(false));
     }
 }
        private void GestureListener_Hold(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
        {
            ArrivalAndDeparture a = (ArrivalAndDeparture)(((FrameworkElement)sender).DataContext);
            MessageBoxResult    r = MessageBox.Show("Notify me when this bus is 5 minutes away?", "Notify me?", MessageBoxButton.OKCancel);

            if (r == MessageBoxResult.OK)
            {
                this.viewModel.SubscribeToToastNotification(a.stopId, a.tripId, 5);
            }
        }
        private void ZoomToBus_Click(object sender, RoutedEventArgs e)
        {
            ArrivalAndDeparture a = (ArrivalAndDeparture)(((FrameworkElement)sender).DataContext);

            if (a.tripDetails != null && a.tripDetails.locationKnown == true && a.tripDetails.coordinate != null)
            {
                GeoCoordinate location = new GeoCoordinate(a.tripDetails.coordinate.Latitude, a.tripDetails.coordinate.Longitude);
                DetailsMap.Center    = location;
                DetailsMap.ZoomLevel = 17;
            }
        }
        public void TripDetailsForArrival(GeoCoordinate location, ArrivalAndDeparture arrival, TripDetailsForArrival_Callback callback)
        {
            string requestUrl = string.Format(
                "{0}/{1}/{2}.xml?key={3}&includeSchedule={4}",
                WebServiceUrlForLocation(location),
                "trip-details",
                arrival.tripId,
                KEY,
                "false"
                );

            HttpWebRequest requestGetter = (HttpWebRequest)HttpWebRequest.Create(requestUrl);

            requestGetter.BeginGetResponse(
                new AsyncCallback(new TripDetailsForArrivalCompleted(requestUrl, callback).HttpWebRequest_Completed),
                requestGetter);
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is ArrivalAndDeparture)
            {
                ArrivalAndDeparture arrival = (ArrivalAndDeparture)value;

                if (arrival.predictedDepartureTime == null)
                {
                    // There is no predicted departure time
                    return(Application.Current.Resources["OBASubtleBrush"]);
                }

                return(Application.Current.Resources["OBADarkBrush"]);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
        public void SwitchToRouteByArrival(ArrivalAndDeparture arrival, Action uiCallback)
        {
            operationTracker.WaitForOperation("StopsForRoute", string.Format("Loading details for route {0}...", arrival.routeShortName));

            StopsForRouteCompleted callback = new StopsForRouteCompleted(this, arrival, uiCallback);

            busServiceModel.StopsForRoute_Completed += new EventHandler <EventArgs.StopsForRouteEventArgs>(callback.busServiceModel_StopsForRoute_Completed);

            Route placeholder = new Route()
            {
                id = arrival.routeId, shortName = arrival.routeShortName
            };

            // This will at least cause the route number to immediately update
            CurrentViewState.CurrentRoute          = placeholder;
            CurrentViewState.CurrentRouteDirection = new RouteStops();

            busServiceModel.StopsForRoute(LocationTracker.CurrentLocation, placeholder);

            ChangeFilterForArrivals(placeholder);
        }
        private void NotifyArrival_Click(object sender, RoutedEventArgs e)
        {
            ArrivalAndDeparture a = (ArrivalAndDeparture)(((FrameworkElement)sender).DataContext);

            this.popup = new Popup();

            NotifyPopup notifyPopup = new NotifyPopup();

            notifyPopup.Notify_Completed += delegate(object o, NotifyEventArgs args)
            {
                if (args.okSelected == true)
                {
                    this.viewModel.SubscribeToToastNotification(a.stopId, a.tripId, args.minutes);
                }

                // This is how we track if the popup is visible
                Dispatcher.BeginInvoke(() => { this.popup.IsOpen = false; });
            };

            this.popup.Child  = notifyPopup;
            this.popup.IsOpen = true;
        }
Esempio n. 8
0
        private void FilterArrivals()
        {
            lock (arrivalsLock)
            {
                UIAction(() => ArrivalsForStop.Clear());

                unfilteredArrivals.Sort(new DepartureTimeComparer());
                foreach (ArrivalAndDeparture arrival in unfilteredArrivals)
                {
                    if (routeFilter != null && routeFilter.id != arrival.routeId)
                    {
                        continue;
                    }

                    ArrivalAndDeparture currentArrival = arrival;
                    UIAction(() => ArrivalsForStop.Add(currentArrival));
                }
            }

            // Refresh NoResultsAvailable status
            OnPropertyChanged("NoResultsAvailable");
        }
        public void TripDetailsForArrival(GeoCoordinate location, ArrivalAndDeparture arrival, TripDetailsForArrival_Callback callback)
        {
            string requestUrl = string.Format(
                "{0}/{1}/{2}.xml?key={3}&includeSchedule={4}",
                WebServiceUrlForLocation(location),
                "trip-details",
                arrival.tripId,
                KEY,
                "false"
                );

            HttpWebRequest requestGetter = (HttpWebRequest)HttpWebRequest.Create(requestUrl);

            requestGetter.BeginGetResponse(delegate(IAsyncResult asyncResult)
            {
                XDocument xmlResponse  = null;
                TripDetails tripDetail = null;

                try
                {
                    xmlResponse = ValidateWebCallback(asyncResult);

                    tripDetail =
                        (from trip in xmlResponse.Descendants("entry")
                         select ParseTripDetails(trip)).First();
                }
                catch (Exception ex)
                {
                    Exception error = new WebserviceParsingException(requestUrl, xmlResponse.ToString(), ex);
                    throw error;
                }

                callback(tripDetail);
            },
                                           requestGetter);
        }
Esempio n. 10
0
 public TripDetailsForArrivalEventArgs(List <ArrivalAndDeparture> arrivals, List <TripDetails> tripDetails)
     : base()
 {
     this.tripDetails = tripDetails;
     this.arrival     = arrival;
 }
        public void TripDetailsForArrival(GeoCoordinate location, ArrivalAndDeparture arrival, TripDetailsForArrival_Callback callback)
        {
            string requestUrl = string.Format(
                "{0}/{1}/{2}.xml?key={3}&includeSchedule={4}",
                WebServiceUrlForLocation(location),
                "trip-details",
                arrival.tripId,
                KEY,
                "false"
                );

            HttpWebRequest requestGetter = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            requestGetter.BeginGetResponse(
                new AsyncCallback(new TripDetailsForArrivalCompleted(requestUrl, callback).HttpWebRequest_Completed),
                requestGetter);
        }
Esempio n. 12
0
        void busServiceModel_ArrivalsForStop_Completed(object sender, EventArgs.ArrivalsForStopEventArgs e)
        {
            Debug.Assert(e.error == null);

            if (e.error == null)
            {
                lock (arrivalsLock)
                {
                    // We are loading arrivals fresh, add all of them
                    if (unfilteredArrivals.Count == 0)
                    {
                        unfilteredArrivals = e.arrivals;
                        FilterArrivals();
                    }
                    else
                    {
                        // We already have arrivals in the list, so just refresh them
                        // Start by updating all the times for all of the arrivals currently in the list,
                        // and find any arrivals that have timed out for this stop
                        List <ArrivalAndDeparture> arrivalsToRemove = new List <ArrivalAndDeparture>();
                        foreach (ArrivalAndDeparture arrival in unfilteredArrivals)
                        {
                            int index = e.arrivals.IndexOf(arrival);
                            if (index >= 0)
                            {
                                ArrivalAndDeparture newArrivalTime = e.arrivals[index];
                                ArrivalAndDeparture currentArrival = arrival;
                                UIAction(() =>
                                {
                                    currentArrival.predictedArrivalTime   = newArrivalTime.predictedArrivalTime;
                                    currentArrival.predictedDepartureTime = newArrivalTime.predictedDepartureTime;

                                    currentArrival.tripDetails.scheduleDeviationInSec = newArrivalTime.tripDetails.scheduleDeviationInSec;
                                    currentArrival.tripDetails.closestStopId          = newArrivalTime.tripDetails.closestStopId;
                                    currentArrival.tripDetails.closestStopTimeOffset  = newArrivalTime.tripDetails.closestStopTimeOffset;
                                    currentArrival.tripDetails.coordinate             = newArrivalTime.tripDetails.coordinate;
                                });
                            }
                            else
                            {
                                // The latest collection no longer has this arrival, delete it from the
                                // list.  Otherwise we will keep it around forever, no longer updating
                                // its time
                                arrivalsToRemove.Add(arrival);
                            }
                        }

                        arrivalsToRemove.ForEach(arrival =>
                        {
                            UIAction(() => ArrivalsForStop.Remove(arrival));
                            unfilteredArrivals.Remove(arrival);
                        }
                                                 );

                        // Now add any new arrivals that just starting showing up for this stop
                        foreach (ArrivalAndDeparture arrival in e.arrivals)
                        {
                            // Ensure that we aren't adding routes that are filtered out
                            if ((routeFilter == null || routeFilter.id == arrival.routeId) &&
                                ArrivalsForStop.Contains(arrival) == false)
                            {
                                ArrivalAndDeparture currentArrival = arrival;
                                UIAction(() => ArrivalsForStop.Add(currentArrival));
                                unfilteredArrivals.Add(currentArrival);
                            }
                        }
                    }
                }
            }
            else
            {
                ErrorOccured(this, e.error);
            }

            operationTracker.DoneWithOperation("ArrivalsForStop");

            // Refresh NoResultsAvailable status
            OnPropertyChanged("NoResultsAvailable");
        }
Esempio n. 13
0
 public StopsForRouteCompleted(RouteDetailsVM viewModel, ArrivalAndDeparture arrival, Action uiCallback)
 {
     this.viewModel  = viewModel;
     this.arrival    = arrival;
     this.uiCallback = uiCallback;
 }
 public TripDetailsForArrivalEventArgs(List<ArrivalAndDeparture> arrivals, List<TripDetails> tripDetails, Exception error)
     : base(error)
 {
     this.tripDetails = tripDetails;
     this.arrival = arrival;
 }
 public StopsForRouteCompleted(RouteDetailsVM viewModel, ArrivalAndDeparture arrival, Action uiCallback)
 {
     this.viewModel = viewModel;
     this.arrival = arrival;
     this.uiCallback = uiCallback;
 }
        public void SwitchToRouteByArrival(ArrivalAndDeparture arrival, Action uiCallback)
        {
            operationTracker.WaitForOperation("StopsForRoute", string.Format("Loading details for route {0}...", arrival.routeShortName));

            StopsForRouteCompleted callback = new StopsForRouteCompleted(this, arrival, uiCallback);
            busServiceModel.StopsForRoute_Completed += new EventHandler<EventArgs.StopsForRouteEventArgs>(callback.busServiceModel_StopsForRoute_Completed);

            Route placeholder = new Route() { id = arrival.routeId, shortName = arrival.routeShortName};
            // This will at least cause the route number to immediately update
            CurrentViewState.CurrentRoute = placeholder;
            CurrentViewState.CurrentRouteDirection = new RouteStops();

            busServiceModel.StopsForRoute(LocationTracker.CurrentLocation, placeholder);

            ChangeFilterForArrivals(placeholder);
        }