Exemple #1
0
        // Returns all bus stops; gets called from MainWindow.cs
        public static List <Stop.stop_t> returnAllBusStops()
        {
            Uri        myUri        = new Uri("http://www.rtd-denver.com/google_sync/VehiclePosition.pb");
            WebRequest myWebRequest = HttpWebRequest.Create(myUri);

            HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;

            // This username and password is issued for the IWKS 4120 class. Please DO NOT redistribute.
            NetworkCredential myNetworkCredential = new NetworkCredential("RTDgtfsRT", "realT!m3Feed");                // insert credentials here

            CredentialCache myCredentialCache = new CredentialCache();

            myCredentialCache.Add(myUri, "Basic", myNetworkCredential);

            myHttpWebRequest.PreAuthenticate = true;
            myHttpWebRequest.Credentials     = myCredentialCache;

            Stop        stop_inst = new Stop();
            FeedMessage feed      = Serializer.Deserialize <FeedMessage>(myWebRequest.GetResponse().GetResponseStream());

            foreach (FeedEntity entity in feed.entity)
            {
                if (entity.vehicle != null)
                {
                    if (entity.vehicle.trip != null)
                    {
                        if (entity.vehicle.trip.route_id != null)
                        {
                            Console.WriteLine("Vehicle ID = " + entity.vehicle.vehicle.id);
                            Console.WriteLine("Current Position Information:");
                            Console.WriteLine("Current Latitude = " + entity.vehicle.position.latitude);
                            Console.WriteLine("Current Longitude = " + entity.vehicle.position.longitude);
                            Console.WriteLine("Current Bearing = " + entity.vehicle.position.bearing);
                            Console.WriteLine("Current Status = " + entity.vehicle.current_status + " StopID: " + entity.vehicle.stop_id);
                            if (Stop.stops.ContainsKey(entity.vehicle.stop_id))
                            {
                                Console.WriteLine("The name of this StopID is \"" + Stop.stops[entity.vehicle.stop_id].stop_name + "\"");

                                var cd = new Stop.stop_t();                     //populates list with stops and their info
                                cd.stop_id   = entity.vehicle.stop_id;
                                cd.stop_name = Stop.stops[entity.vehicle.stop_id].stop_name;
                                cd.stop_lat  = Stop.stops[entity.vehicle.stop_id].stop_lat;
                                cd.stop_long = Stop.stops[entity.vehicle.stop_id].stop_long;
                                allstops.Add(cd);

                                Console.WriteLine("The Latitude of this StopID is \"" + Stop.stops[entity.vehicle.stop_id].stop_lat + "\"");
                                Console.WriteLine("The Longitude of this StopID is \"" + Stop.stops[entity.vehicle.stop_id].stop_long + "\"");
                                string wheelChairOK = "IS NOT";
                                if (Stop.stops[entity.vehicle.stop_id].wheelchair_access)
                                {
                                    wheelChairOK = "IS";
                                }
                                Console.WriteLine("This stop is " + wheelChairOK + " wheelchair accessible");
                            }

                            Console.WriteLine("Trip ID = " + entity.vehicle.trip.trip_id);
                            if (Trip.trips.ContainsKey(entity.vehicle.trip.trip_id))
                            {
                                if (entity.vehicle.current_status.ToString() == "IN_TRANSIT_TO")
                                {
                                    if (Stop.stops.ContainsKey(entity.vehicle.stop_id))
                                    {
                                        Console.WriteLine("Vehicle in transit to: " + Stop.stops[entity.vehicle.stop_id].stop_name);
                                        Trip.trip_t trip = Trip.trips[entity.vehicle.trip.trip_id];
                                        foreach (Trip.trip_stops_t stop in trip.tripStops)
                                        {
                                            // Console.WriteLine(stop.stop_id);      //should print whole trip with names of stops, only prints ID's
                                            foreach (Stop.stop_t s in allstops)
                                            {
                                                if (stop.stop_id == s.stop_id)      //dosent work correctly
                                                {
                                                    //      Console.WriteLine(s.stop_name);
                                                }
                                            }


                                            if (stop.stop_id == entity.vehicle.stop_id)
                                            {
                                                Console.WriteLine(".. and is scheduled to arrive there at " + stop.arrive_time);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(allstops);
        }
Exemple #2
0
 public static int CompareTwoStops(Stop.stop_t s1, Stop.stop_t s2)
 {
     return(s1.stop_name.CompareTo(s2.stop_name));
 }