How it works
The library uses XML serialisation to extract objects from the REST API.
It then uses the Reactive Extensions system to publish these objects.
There are four feeds provided by the library
  • Line Status
  • Station Incidents
  • Station Names
  • Train Prediction
  • Station Arrivals - This uses the Tfl Train prediction REST API to provide information on arrivals for a specified station

Example code

Initialisation

CancellationTokenSource token = new CancellationTokenSource();
TfL.TrackerNet tracker = new TrackerNet("http://cloud.tfl.gov.uk/TrackerNet/", "http://webservices.lul.co.uk/");

Line Status

var lineStatus = from s in tracker.LineStatus.Poll(token.Token, 1000)
                             select s;
lineStatus.Subscribe((status)=> status.ForEach(System.Console.WriteLine));

Station Status

var feed = from s in tracker.StationStatus.IncidentsOnly.Poll(token.Token, 30000)
                 select s;
feed.Subscribe(System.Console.WriteLine);

Station Names

var stationNames = tracker.StationNames.Poll();
stationNames.Subscribe(System.Console.WriteLine);

Train times ( per line, filtered by station)

var trainTimes = from t in tracker.TrainTimes("District").Poll()
                       where t.Name == "Victoria."
                       select t;
trainTimes.Subscribe(System.Console.WriteLine);

Train times ( specified station, all lines)

var stationTimes = from t in tracker.StationArrivals("Victoria").Poll()
                           select t;
stationTimes.Subscribe(System.Console.WriteLine);

Poll method

There are two overloads of the Poll method. With no parameters the API is polled only once.
The other overload runs a task periodically using the period parameter. A cancellation token is used to cancel this operation.

Last edited Dec 29, 2011 at 11:56 AM by msrushton, version 2

Comments

No comments yet.