Technical Report Supervisor: Jonathan Lambert
TABLE OF CONTENTS... 2 1 EXECUTIVE SUMMARY... 4 2 INTRODUCTION... 4 2.1 BACKGROUND AND RELATED WORK... 4 2.1.1 State-of-the Art: Existing APIs and Technologies... 4 Transport and Travel Specific API s... 5 API Transport for London... 5 API Metro Trip Planner... 6 2.1.2 Current Position: CIE Group of Companies... 6 2.2 AIMS... 6 2.3 TECHNOLOGY OVERVIEW... 7 3 SYSTEM... 7 3.1 STRUCTURE... 7 3.2 REQUIREMENTS... 8 3.2.1 Functional Requirements... 8 3.2.2 Data Requirements... 9 3.2.3 User Requirements... 10 3.2.4 Environmental Requirements... 10 3.2.5 Interface Requirements Applications/Systems which interface with the API... 10 3.3 DESIGN AND ARCHITECTURE... 12 3.3.1 API... 13 (1) Class Diagrams... 13 (2) Use Case Diagrams... 14 a. API Overview... 14 b. Irish Rail... 15 Station Information... 15 Schedule Information... 15 Realtime Information... 15 Delay Information... 15 Passenger Numbers Information... 16 c. Dublin Bus... 16 Route Information... 16 Schedule Information... 16 Fare Information... 16 d. Bus Éireann... 17 Route Information... 17 Schedule Information... 17 (3) Sequence Diagrams... 18 a. Irish Rail... 18 Station Information... 18 Schedule Information... 18 Realtime Information... 19 Delay Information... 19 Passenger Numbers Information... 20 b. Dublin Bus... 20 Route Information... 20 Schedule Information... 21 Fare Information... 21 c. Bus Éireann... 22 2
Route Information... 22 Schedule Information... 22 3.4 IMPLEMENTATION - TECHNOLOGIES AND METHODOLOGIES... 23 3.4.1 Technology Overview... 23 3.4.2 API Technologies... 23 3.4.2.1 Microsoft Visual Web Developer 2010 Express /.NET Framework 4.0... 23 3.4.2.1.1 Installation and Configuration of Microsoft Visual Web Developer /.NET Framework 4.0... 24 3.4.3 API Procedures Development of the Ireland Transport API Web Service Application... 26 3.4.3.1 REST... 26 3.4.3.2 Microsoft Windows Communication Foundation (WCF)... 27 3.4.3.2.1 The Interface File... 27 3.4.3.2.2 The Service File... 28 3.4.4 Database Technologies... 28 3.4.4.1 Microsoft SQL Server 2008 R2... 28 3.4.4.1.1 Installation and Configuration of Microsoft SQL Server 2008 Express... 28 3.4.5 Database Procedures... 29 3.4.5.1 Creating a Database... 29 3.4.5.1.1 ** LINQ to SQL... 31 3.4.6 Mobile Application Technologies... 32 3.4.6.1. Eclipse IDE / Android Development Tools... 32 3.4.6.1.1 Installation and Configuration of Eclipse IDE with Android Development Tools... 32 3.4.7 Mobile Application Procedures Development of the Android Mobile App... 35 3.4.7.1 Eclipse Android Application Project... 35 3.4.7.1.1 Proof of Concept: Development of an Irish Rail Taxi App... 36 3.5 TESTING... 39 3.6 GRAPHICAL USER INTERFACE (GUI) LAYOUT... 40 4 CONCLUSION... 41 4.1 MILESTONES AND HURDLES... 41 4.2 FUTURE PROSPECTS... 42 APPENDIX 1: PROJECT PROPOSAL... 43 APPENDIX 2: PROJECT PLAN... 46 APPENDIX 3: REQUIREMENTS SPECIFICATION... 47 APPENDIX 4: CODE SEGMENTS... 52 4.1 API (C#)... 52 4.2 DATABASE (SQL)... 66 APPENDIX 5: OTHER MATERIAL USED... 71 5.1 DOCUMENTATION GENERATION SOFTWARE... 71 5.1.1 Sandcastle / Sandcastle Help File Builder... 71 BIBLIOGRAPHY... 72 3
With the proliferation of the Smartphone and specifically the emergence of the mobile app some of the focus has moved from the Internet as being a vast source of data for lookup purposes to in effect the World Wide Web becoming itself a development platform. This report presents the Ireland Transport Network API, an application programming interface, as a bridge to facilitate the seamless interaction of for example, mobile applications and a transport data store. The report will outline: the need and reasoning behind its development; the services provided; the technologies and methodologies it implements and will discuss the benefits it will provide for its stakeholders namely: the CIE Group of companies: Irish Rail; Dublin Bus and Bus Éireann whose data the API will expose; the mobile application developers who will make use of its services in the development of a variety of rich applications; end users who will ultimately benefit from these applications. We will evaluate the Ireland Transport API based on existing APIs provided by a number of International transport companies and discuss how it will compare to these in terms of the services provided. We will also outline the development of a number of mobile applications, as a proof-of-concept, which will demonstrate the use of the API. 2.1 Background and Related Work With the proliferation of the Smartphone and specifically the emergence of the mobile App some of the focus has moved from the Internet as being a vast source of data for lookup purposes to in effect the World Wide Web becoming itself a development platform. Methods of exposing raw data including RSS feeds and web services have gained widespread popularity in the last number of years. These technologies allow an organisation to expose their valued business data in a structured, yet raw format making this data freely accessible through appropriate data transfer protocols. As a result this data can form the source data for any number of rich mobile applications. The ability for an organisation to seamlessly expose its data in a structured way benefits both the organisation as well as their customers. For example, a transport company is a good example of an organisation which can benefit greatly from exposing their data in such a manner. The exposing of data such as schedules, fares, seat availability as well as up-to the minute real-time information is ideal for source data in a variety of useful public service applications; it is proven that these applications will be developed provided the source data is made freely available. It is the combination of firstly, the numerous organisations with vast amounts of data worth exposing, and secondly the ever growing popularity of mobile application development which leads to the area of API development being one of the fastest growing in the IT industry. Organisations with an API exposing their data in a structure they themselves determine pave the way for the development ofa series of mobile apps which ultimately benefit their customers. 2.1.1 State-of-the Art: Existing APIs and Technologies An API or Application Programming Interface is a software-to-software interface aimed primarily at software developers allowing for the development of systems which are powered by the services contained in the API. APIs allow separate applications to communicate by defining the instructions and standards which allow for this communication. 4
APIs from every conceivable background are continually being developed exposing data which forms the source data for any number of applications from Media and Social Networking related systems or Sports and Music related systems to public information systems such as the Ireland Transport API. The volume of APIs is ever growing which means the standard is continually improving and newer technologies are being developed. www.programmableweb.com, a useful resource in the area of API research is a directory which contains information on hundreds of public API s across a huge variety of categories, from Advertising, Shopping, Gaming, Chat, Real Estate, Food virtually every area of every industry has representation in some form in the API directory. Figure 1.0 was taken from the programmableweb website and shows the most popular API s being used by developers today. Figure 1.0 Most popular API s in use today From the chart above we can see the Facebook API is currently being used by 20% of the developers who are registered with the programmableweb website. Facebook released their API in 2007 and it has quickly become one of the most widely used among website developers, the Facebook API allows a website developer to easily make use of many of the Facebook features available to members of the Facebook Social Network. Developers can add a social context to their applications by making use of profiles, friends, groups and photos. The Facebook API is built using the REST architecture for web service development and the data responses it generates are in XML format. (Facebook API Home, 2011) Transport and Travel Specific API s There are over 70 API s specific to the Travel and Transport industry. These APIs show the industry standard and looking more closely at a number of these APIs we can see how the Ireland Transport Network API fits into this standard. (www.programmableweb.com, 2011) API Transport for London The Transport for London API provides information on all forms of public transport in London, routes, schedules and journey planner information is available as well as up to date station closure information allowing people to plan their travel and avoid disruption. The Protocol used in the Transport for London API is REST which defines an architectural style based on a number of constraints which allows for the transfer of data over the World Wide Web. The Response Data Format is XML. 5
(Transport For London on www.programmableweb.com, 2011) (Transport For London - Home, 2011) API Metro Trip Planner Metro trip planner provides trip planning, as well as transport project information for the Los Angeles County. The API publishes data which describe the Metro s routes, schedules and stops. The Protocol used in the Metro Trip Planner API is REST which defines an architectural style based on a number of constraints which allows for the transfer of data over the World Wide Web. The Response Data Format can be any one of XML, JSON or PHP. (Metro Trip Planner on www.programmableweb.com, 2011) (Metro Trip Planner - Home, 2011) 2.1.2 Current Position: CIE Group of Companies Irish Rail, Dublin Bus and Bus Éireann are semi-state bodies that are mandated by the state to provide public transport in Ireland, through the provision of both Rail and Bus services. Management and coordination of all informational aspects of this transport infrastructure are provided through dedicated database resources. To date, access to all information has been restricted to internal audits with the exception of data and information published through the Irish Rail, Dublin Bus and Bus Éireann public websites. The advancements in web-technologies and in particular mobile communications have meant that there is a constant requirement for any-time any-place information. These technologies to-date have been excluded from exploiting the vast repository of dynamic information stored within Irish Rail, Dublin Bus and Bus Éireann information systems. This project attempts to address this issue through the development of a working model of an Ireland Transport Application Programming Interface (API). The interface will provide a Web Service API for use by mobile application developers, allowing developers to create applications that provide dynamic transport related information to their users. The intention is to expose data from the Irish Rail, Dublin Bus and Bus Éireann legacy systems allowing for ease of access. 2.2 Aims This project will also include the development of a mobile application as a proof-of-concept for the developed API. In particular, the application will demonstrate the features and use of the interface. This section outlines the aims of this project, it describes what is hoped will be achieved in the course of the development of the Ireland Transport Network API and the Proof-of-Concept Android App. The main aim of this project is to produce a working model of a RESTful WCF Web Service API, namely the Ireland Transport Network API. The function of this API is to knit together a variety of systems which broadly replicate the legacy systems which exist across the CIE Group of companies. In reality, these systems are responsible for such things as Seat Reservation on Irish Rail Services, managing train movements and scheduling Dublin Bus and Bus Éireann services, the data contained within these systems has huge potential as source data for a wide variety of useful applications should that data be made available in a structured way. This concept forms the basis of the ever growing App development market. Companies exposing their data in a structured way allowing for the development of applications benefiting their customers but with little or no expense to the company themselves, the company chooses what data to expose and how it should be exposed meaning they maintain full control of their data. The development of an API which fits this model is the aim of this project. 6
A smaller part of this project involves the development of an Android App, the purpose of which is to demonstrate the potential of the API It should be noted that the network of systems which will provide the source data for the API is loosely based on the real systems architecture within the CIE Group of companies but is not an exact replica. 2.3 Technology Overview The approach taken in the development of the API was a Microsoft.NET approach; this involved the installation and configuration of a number of Microsoft and third party development tools which integrate seamlessly to create a complete API development environment. The approach taken for the development of the mobile app was a Java approach; this involved the installation and configuration of the Eclipse IDE together with the Google Android Development Tools (ADT) plug-in which again provide everything necessary for the development of a mobile application which can be easily deployed to any Google Android phone. In this chapter we will firstly outline the structure of this technical report, we will present a detailed description of the requirements for both the Ireland Transport Network API and the proof of concept Android App, secondly we will look at the Design and Architecture of the System and how the different components knit together to form the overall working environment, thirdly we will look in detail at the technologies and methodologies employed in the implementation of both systems, next we will discuss the testing methods employed throughout the development process and lastly we will describe the Graphical User Interface namely the API Home website which acts as a public portal to the API. 3.1 Structure This paper is structured to best describe the processes undertaken in the development of the Ireland Transport Network API. The Introduction above gave a brief description of the concepts behind the project, the reason for the choice of the API as the project as well as an overview of the current environment with regard to the CIE Group of companies as well as what is available in terms of the current stateof the-art API s being used in real world situations today. The remainder of this paper is structured as follow; in section 3.2 we outline the Requirements of the system, we will discuss the Design and Architecture in section 3.3 and present the UML Diagrams created as part of the design stage of the development process, in section 3.4 we will take a in depth look at the technologies and methodologies used in the Implementation of the API and the demonstrating Google Android App. In section 3.4 we outline the Testing which was undertaken and section 3.5 is concerned with describing the Graphical User Interface or the public front of the API in the form of the Ireland Transport Network API Home website which acts as an information portal for the API; In the Conclusion section 4 we describe the outcome of the development of the API and the Android App, the experience gained, the milestones reached as well as the hurdles encountered in the course of the development as well as how these problems were overcome. In this section we discuss the commercial potential of the project as well as the potential for future enhancements. The Appendix contains a variety of reference material including the Proposal, Requirements Specification and Project Planning documentation previously submitted, it also contains all code segments along with explanatory comments. 7
3.2 Requirements Requirements Specification is generally one of the first activities carried out in the Software Development Lifecycle; it is the process of determining what the systems capabilities should be from a number of different perspectives. In this subsection we will firstly discuss the initial requirements gathering techniques employed before categorising and focussing more specifically on the Functional Requirements, Data Requirements, User Requirements, Environmental Requirements and Interface Requirements for both the Ireland Transport Network API and the proof-of-concept Android App. In order to elicit the requirements for this project, discussions were held with a number of mobile application developers who have developed mobile applications providing real-time train information through iphone and Google Android devices. This real-time information is currently available via RSS feed on the Irish Rail website. However real-time information is currently the only information available through these means. In the course of the discussions a number of suggestions were made regarding the potential for countless more useful applications should Irish Rail, Bus Éireann and Dublin Bus make available more legacy system data. The suggestions which repeatedly came up in the course of these discussions will form the catalogue of services which the API will provide and therefore fall into the category of our functional requirements 3.2.1 Functional Requirements In this section we present the functional requirements of the Dublin Transport Web Service API outlining the functions which the API will provide and also the functional requirements of the proof-of-concept Android App which demonstrates the use of the API. A Functional Requirement is simply a statement of what the system must do, functional requirements relate directly to the processes which the system has to perform, from the perspective of the Ireland Transport Network API the functional requirements are the web services which comprise the API. Irish Rail Stations: The API will provide station information including station id, station code, station description, and station latitude and longitude. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/iestations Irish Rail Schedule: The API will provide schedule information including a string representing the service (origin to destination) and schedule time. The user will provide the origin code and the destination code as well as the date for which the schedule is required. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/ieschedule/mhide/gstns/1-jun-2011 Irish Rail Realtime Information: The API will provide up to the minute realtime information including the schedule arrival time, a string representing the train journey and the expected arrival time. The user will provide the station code of the station for which the realtime information is required. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/ierealtime/cnlly Irish Rail Delay Information: The API will return up to the minute information on currently delayed trains the information returned includes the current location of the train, a string representing the train journey, the scheduled arrival time, the number of minutes delayed and the expected arrival time. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/iedelays Irish Rail Passenger Numbers: The API will provide details on numbers of passengers booked on trains arriving into all stations. The information includes the station name and the number of passengers. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/iepassengernumbers Dublin Bus Routes: The API will provide route information on all Dublin Bus routes. The information includes the route number and a string representing the journey (origin to destination). The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/dbroutes 8
Dublin Bus Schedule: The API will provide schedule information for a specified route on a specified date. The information includes the route number and a string representing the journey (origin to destination) and the schedule time. The user provides the route and date for which the schedule is required. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/dbschedule/45/1-jun-2011 Dublin Bus Fares: The API will provide fare information Dublin Bus journeys based on the number of stages being travelled. The information includes a string representing a description of the fare (e.g. Adult 1 3 stages) and the fare. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/dbfares Bus Éireann Routes: The API will provide route information on all Bus Éireann routes. The information includes the route number and a string representing the journey (origin to destination). The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/beroutes Bus Éireann Schedule: The API will provide schedule information for a specified route on a specified date. The information includes the route number and a string representing the journey (origin to destination) and the schedule time. The user provides the route and date for which the schedule is required. The information will be provided in either XML or JSON format; Requesting URL: http://www.cie.ie/api/irelandtransportapi/itnservice.svc/xml/beschedule/100/1-jun-2011 Proof-of-Concept Android App In order to demonstrate the API through a real world system a second component of this project will be the development of a Google Android mobile application, specifically, an application aimed at Taxi drivers in the Dublin area which would inform them of numbers of passengers arriving in the various train stations around the city within a specified timeframe allowing for informed choices as to where they can best position themselves for maximum customer numbers. 3.2.2 Data Requirements In this section we present the Data Requirements of the Dublin Transport Web Service API outlining the data sources which replicate the CIE Group of Companies legacy systems. These data sources are implemented as a series of SQL Server 2008 databases. IR_SeatRes: The IR_SeatRes database will replicate the Irish Rail Seat Reservation System which is the system allowing for customer reservations on Irish Rail services. This database contains the table s tbl_trainstations and, tbl_bookings and the stored procedures spgetstations and spgetpassengernumbers which are the queries feeding the Get Stations and Get Passenger Numbers web services; IR_Schedule: The IR_Schedule database will replicate the Irish Rail Journey Planner System which is the system which produces Irish Rail schedules. This database contains the table tbl_trainschedule and the stored procedure spgetscheduleinformation which is the query feeding the Get Irish Rail Schedule web service; IR_Realtime: The IR_Realtime database will replicate the Irish Rail Realtime System which is the system managing train movements on an on-going basis. This database contains the table tbl_rtstations, tbl_rttrainheaders, tbl_rttrainreporting and tbl_rttraintimetable and the stored procedures spgetdelayedtrains and spgetstationrealtimedata which are the queries feeding the Get Realtime Information and Get Delay Information web services; DB_Main: The DB_Main database will replicate the main source of Data for the Dublin Bus public websites. This database contains the table tbl_dbroutes and the stored procedure spdb_getroutes which is the query feeding the Get Dublin Bus Routes web service; DB_Scheduler: The DB_Scheduler database will replicate the Dublin Bus Scheduling System which is the system which produces Dublin Bus schedules. This database contains the table tbl_busschedule and the stored procedure spgetdbscheduleinformation which is the query feeding the Get Dublin Bus Schedule web service; DB_Fares: The DB_Fares database will replicate the Dublin Bus Fares Engine System which is the system which manages Dublin Bus fares. This database contains the table tbl_dbfares and the stored procedure spdb_getfares which is the query feeding the Get Dublin Bus Fares web service; 9
BE_Main: The BE_Main database will replicate the main source of Data for the Bus Éireann public websites. This database contains the table tbl_beroutes and the stored procedure spbe_getroutes which is the query feeding the Get Bus Éireann Routes web service; BE_Scheduler: The BE_Scheduler database will replicate the Bus Éireann Scheduling System which is the system which produces Bus Éireann schedules. This database contains the table tbl_busschedule and the stored procedure spgetbescheduleinformation which is the query feeding the Get Bus Éireann Schedule web service. 3.2.3 User Requirements In this section we present the User Requirements of the Dublin Transport Web Service API outlining the behaviour required by the user of the system as well as the behaviour which a user expects from the system User Request: The request from the external application is made in the form of a RESTful URL which specifies the particular web service being called as well as the user defined response data format (XML or JSON); User Response: The Response from the web service should be in either XML or JSON format; Legacy Systems Data: The data contained in the CIE Group of companies legacy systems should be exposed in a structured manner; API Home: The User Guide and all relevant API information should be available via a public API Home website; this website should contain amongst other things a dedicated developers section detailing technical information on the process of requesting and implementing web service feeds. 3.2.4 Environmental Requirements In this section we present the Environmental Requirements outlining the environmental settings required for the system to function correctly, this may include the setup and configuration requirements of a potential host system. Physical Environment: The Ireland Transport API was developed on a DELL Inspiron M101Z with AMD Athlon II Neo processor model K125, 2GB RAM and 218GB Hard Drive and running Windows 7 64-bit Home Premium; Web Service API Server Environment: The setup of the Ireland Transport Web Service API server component should include Web Server for example IIS, configured to run.net alongside SQL Server 2008. The API should be accessible remotely; Requesting Client Environment: In order to access a function which exists in another application the client application should be configured to send web service requests and accept web service responses this includes a reliable internet connection. 3.2.5 Interface Requirements Applications/Systems which interface with the API In this section we present the Interface Requirements of the Dublin Transport Web Service API outlining the legacy systems which interface with the API; these systems form the source data which is structured and exposed producing the API. External Application / Mobile Device: The user interacts with the system via a client application for example an app residing on a Google Android mobile device. This client application makes RESTful calls to the Web Service API and the response from the API is in one of two formats XML or JSON specified in the client request; SQL Server :The API queries the Irish Rail/Dublin Bus/Bus Éireann database to get API information; Irish Rail Legacy System Seat Reservation System: The Seat Reservation System is an internal application which manages the process of a customer booking a seat on a train, whether via the website, the booking office or the telesales systems. The information which the Dublin Transport Web Service API will obtain from the Seat Reservation System includes passenger numbers as well as schedule and journey planner information; 10
Irish Rail Legacy System Train Operating and Performance System / Realtime System: The Train Operating and Performance System is an internal application which manages the movements of trains around the Irish Rail network.. The Ireland Transport Web Service API will obtain Real-time information from this system; Irish Rail Legacy System Irish Rail Scheduler System: The Irish Rail Scheduler System is built to replicate the Irish Rail Journey Planner which contains schedule information for all Irish Rail trains. The Ireland Transport Network Web Service API will obtain schedule information from this system; Dublin Bus Legacy System Dublin Bus Main: The Dublin Bus Main database is the main source of data behind the public Dublin Bus website. The Ireland Transport Network API will obtain information on all Dublin Bus routes from this database; Dublin Bus Legacy System Dublin Bus Scheduler: The Dublin Bus Scheduler database is built to replicate a scheduling system providing times of buses for a specified route on a specified date. The Ireland Transport Network API will obtain Dublin Bus schedule information from this database; Dublin Bus Legacy System Dublin Bus Fares Engine: The Dublin Bus Fares database is an internal application for managing fares for Dublin Bus journeys. The Ireland Transport Network API will obtain information on all Dublin Bus fares based on the stages being travelled from this database; Bus Éireann Legacy System Bus Éireann Main: The Bus Éireann Main database is the main source of data behind the public Bus Éireann website. The Ireland Transport Network API will obtain information on all Bus Éireann routes from this database; Bus Éireann Legacy System Bus Éireann Scheduler: The Bus Éireann Scheduler database is built to replicate a scheduling system providing times of buses for a specified route on a specified date. The Ireland Transport Network API will obtain Bus Éireann schedule information from this database. 11
3.3 Design and Architecture In this section we will firstly present a high level overview of the design and architecture of the Ireland Transport Network Web Service API before The architecture of the API provides a conceptual model of the system and clearly defines the relationships between the individual elements which make up the overall application. As can be seen in Figure 2.0 the API provides an interface for communications between the CIE Group companies legacy systems and the numerous web and mobile applications which require access to these legacy systems data through RESTful requests. The API exposes the data in a structured format by tying together these systems data and exposing it through a library of useful web services. Figure 2.0 Architecture of the Ireland Transport Network Web Service API 12
3.3.1 API (1) Class Diagrams 13
(2) Use Case Diagrams a. API Overview 14
b. Irish Rail Station Information Schedule Information Realtime Information Delay Information 15
Passenger Numbers Information c. Dublin Bus Route Information Schedule Information Fare Information 16
d. Bus Éireann Route Information Schedule Information 17
(3) Sequence Diagrams a. Irish Rail Station Information Schedule Information 18
Realtime Information Delay Information 19
Passenger Numbers Information b. Dublin Bus Route Information 20
Schedule Information Fare Information 21
c. Bus Éireann Route Information Schedule Information (Dennis, Haley Wixom, & Tegarden, 2005) (Ambler, 2007) 22
3.4 Implementation - Technologies and Methodologies The purpose of this section is to outline the technologies and methodologies used in the implementation of the Ireland Transport Web Service API and also the Google Android App whose purpose is to demonstrate the use of the API. This section will also act as an installation and configuration guide for the setup of the development environment used in the development process. In this section we will evaluate the technologies and methodologies used and explain the reasoning behind the choice of technologies. 3.4.1 Technology Overview The approach taken in the development of the API was a Microsoft.NET approach; this involved the installation and configuration of a number of Microsoft and third party development tools which integrate seamlessly to create a complete API development environment. The approach taken for the development of the mobile app was a Java approach; this involved the installation and configuration of the Eclipse IDE together with the Google Android Development Tools (ADT) plug-in which again provide everything necessary for the development of a mobile application which can be easily deployed to any Google Android phone.. These tools as well as their setup and configuration instructions are outlined in detail below. 3.4.2 API Technologies In this section we describe in detail the technologies used in the development of the API. 3.4.2.1 Microsoft Visual Web Developer 2010 Express /.NET Framework 4.0 The RESTful services which comprise the Ireland Transport API are implemented in Windows Communication Foundation (WCF) Web Services developed in Microsoft Visual Web Developer 2010 Express. Microsoft Visual Web Developer 2010 Express, a lightweight version of the Microsoft Visual Studio line of products is a freeware Integrated Development Environment (IDE) which can be used to develop websites, web applications and web services for all platforms supported by the.net Framework, it was chosen as the preferred IDE for the development of the API as it is the standard IDE for the development of.net applications which was the selected development framework for the API due to the fact that the existing Irish Rail / Bus Éireann and Dublin Bus systems which the API will interface with are.net based systems. ** The Visual Studio Development Server Microsoft Visual Web Developer 2010 Express includes the Visual Studio Development Server, a local web server specifically built to serve, or run ASP.NET Web pages on the local computer but will not serve pages to another computer or outside of the application scope. The Visual Studio Development Server provides an efficient way to test pages locally before publishing to a production server running Microsoft Internet Information Services (IIS). During the course of the development of the API the services were tested on the Visual Studio Development Server ** Internet Information Server (IIS) Microsoft Internet Information Server is a Web Server application and set of feature extension modules for running web applications on the internet. When the API was complete the application was set up to run on Microsoft IIS rather than the local Visual Studio Development Server. 23
3.4.2.1.1 Installation and Configuration of Microsoft Visual Web Developer /.NET Framework 4.0 This section outlines the step by step process employed in the setup of our environment for the development of the API Step 1 Download Application ** For ease of installation, firstly download the Microsoft Web Platform Installer (WebPI) tool from the following location (http://www.microsoft.com/web/downloads/platform.aspx), The Microsoft Web Platform Installer tool makes getting the latest components of the Microsoft Web Platform (e.g. Web Developer, SQL Server, Internet Information Services(IIS)) easier; Figure 3.0 Microsoft Web Platform Installer Secondly download Microsoft Visual Web Developer 2010 Express installation file (wpilauncher_n.exe) from the following location (http://www.microsoft.com/express/downloads/#2010-visual-web-developer) ; Installation begins with the execution of the installation file (wpilauncher_n.exe), on execution a user interface will appear to guide you through the installation. Figure 6.0 shows the initial Graphical User Interface seen when Microsoft Visual Web Developer is installed. 24
Figure 4.0 Microsoft Visual Web Developer Express Step 2 Create the WCF Web Service Application Project Select File >> New Project; Figure 5.0 New WCF Web Service Application Under Visual C# select WCF Web Service Application. 25
3.4.3 API Procedures Development of the Ireland Transport API Web Service Application In this section we describe in detail the procedures and methodologies used in the development of the API. 3.4.3.1 REST In this section we introduce the fundamental principles of Representational State Transfer (REST), a design architecture for building web services the Web way. The Web has become the most successful distributed computing platform ever developed and REST can be described as a way of designing services to work the way the web works. REST is not tied to any particular technology or platform but rather defines a set of rules which if adhered to result in a RESTful service. REST is the architecture on which the World Wide Web itself is built and also is the core methodology used in the Ireland Transport Network API; this decision was based on the popularity of REST in the development of APIs today. REST is also the protocol used in the vast majority of similar international transport related APIs REST is built around the concept of Resources, a resource can be described as any meaningful concept which may be addressed and is identified by a URI for example, http://www.example.org. Requests and responses in this client-server architecture are concerned with the transfer of representations of resources. A representation of a resource is typically a document for example, a web page, which represents the current state of the resource.. REST is considered a more lightweight alternative to SOAP, it has human readable results and is considered easy to implement unlike the SOAP alternative which requires expertise in a variety of rigid development tools (Flanders, 2009) (Designing and Building RESTful Web Services) REST defines a number of constraints and an application conforming to these constraints is described as being RESTful, these constraints are outlined in Table 1.0 Separation of Concerns: Clients are not concerned with such things as data storage and servers are not concerned with such things as user interface. For Example: A Client Server architecture; Stateless: The client-server communication is further constrained by the fact that no client information is stored on the server between requests. Each request is an independent unit containing all the information needed to service the request; Cacheable: Responses must be cacheable meaning the client should be able to store response information in their cache which can improve performance. For Example: The World Wide Web; Layered system / Transparency: A client cannot tell and does not need to know if it is connected directly to the server or to an intermediary application between it and the server; Uniform Interface: A uniform interface between client and server keeping the resources and representations separate. For Example: A web service would not return the contents of its database but rather a representation of this data in HTML/ XML/ JSON format. Table 1.0 REST Constraints 26
(REST Architecture Style, 2000) Our implementation of the Ireland Transport Network Web Service API conforms to these constraints as such it can be said to be a RESTful Web Service API. 3.4.3.2 Microsoft Windows Communication Foundation (WCF) WCF or Windows Communication Foundation is Microsoft s next-generation development platform for building, configuring and deploying cross-network services. WCF is the successor to the popular set of technologies which have been used successfully by developers over the past decade in the development of distributed applications. These technologies include ASP.NET Web Services (ASMX) along with the Web Service Enhancements (WSE) extensions, Microsoft Message Queue (MSMQ), the COM+ runtime environment and.net Remoting. The goal of WCF was to provide one technology encompassing all of the best features of these separate technologies. A reliable single technology providing the ability to create a web service with reliable communication supporting sessions and allowing for the inspection of raw data flowing through the system all of which were available but through the more complex process of combining multiple technologies. The basic building blocks of a WCF Service application are presented in Table 2.0 Address where is the service; Binding how do I communicate with the service; Contract what can the service will provide for the implementer. Table 2.0 WCF Application Creating a new WCF Service Application provides a template solution consisting of an interface file (.cs) as well as a service file (.svc) and a configuration file web.config which contains configuration details including information about the End Point as well as Service and End Point behaviour. 3.4.3.2.1 The Interface File The interface file (See Code Segment 1) is the Service Contract which defines the methods the Web Service will provide and also outlines such details as the HTTP method being used, the return data format and the Uri which will form part of the client request. Sample method definitions for the services returning Dublin Bus route information is presented in Code Segment 1.0 Code Segment 1.0 Interface File Method Definitions [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/dbroutes")] List<objRoute> getdbroutesxml(); [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/dbroutes")] List<objRoute> getdbroutesjson(); 27
3.4.3.2.2 The Service File The service file (See Code Segment 2) is the implementation of the Service Contract providing the functionality for retrieving the route data from the Dublin Bus database. To use the Dublin Bus routes example the functionality works as follows. Both getdbroutesxml() and getdbroutesjson() call a common getdbroutes() method which creates a generic list of objroute objects from data retrieved from the Dublin Bus database using LINQ to SQL technologies An objroute object is an instance of the serialized objroute class which defines a Dublin Bus route containing the properties routeid and routedescription, this class is serialized to allow it to be stored in a format allowing for transmission over a network in this case the Internet Sample code for this getdbroutes() implementation method using the LINQ native query language is presented in Code Segment 2.0 Code Segment 2.0 Method Implementation - LINQ public List<objRoute> getdbroutes() { List<objRoute> dbroutes = new List<objRoute>(); var db_dbmain = new DB_MainDataContext(); var dbroutesquery = db_dbmain.spdb_getroutes(); foreach (var route in dbroutesquery) { objroute myroute = new objroute(route.dbroutenumber, route.dbroutedescription); dbroutes.add(myroute); return dbroutes; See Appendix 5.1 for the complete C# WCF Application code 3.4.4 Database Technologies In this section we describe in detail the technologies used in the development of the databases which replicate the CIE Group Companies legacy systems. 3.4.4.1 Microsoft SQL Server 2008 R2 Microsoft SQL Server 2008 Express is a freeware relational database server for developing and deploying desktop, web and small server applications. It comes with a 10GB database storage facility and installation includes the SQL Server Management Studio Database Management System (DBMS) using Transact-SQL (T-SQL) as its primary query language. It is a lightweight version of Microsoft SQL Server Relational Database. The existing CIE Group systems which will interface with the Ireland Transport API currently use SQL Server databases for their data storage; this led to the choice of SQL Server as the selected database for the API. These databases are modelled in the API application using the LINQ to SQL Framework. 3.4.4.1.1 Installation and Configuration of Microsoft SQL Server 2008 Express This section outlines the step by step process employed in the setup of our environment for the development of our databases which act as replicas of the CIE Group Legacy Systems whose data the API will expose 28
Step 1 Download Application Download the SQL Server 2008 R2 Express installation file (SQLEXPRWT_x86_ENU.exe) from the following location (http://www.microsoft.com/express/database/); Installation begins with the execution of the installation file (SQLEXPRWT_x86_ENU.exe), on execution a user interface will appear to guide you through the installation. Figure 6.0 shows the initial Graphical User Interface seen when SQL Server is installed. Figure 6.0 SQL Server 2008 Step 2 Create an ODBC Connection Creating an ODBC connection allows for a DSN-less connection from the WCF application to the database meaning the application can connect directly to the database without having to supply database connection credentials in the applications configuration file. An ODBC connection is normally used when an application needs to access a database on a database server which is not local to the machine on which the application is running. To create an ODBC Connection : Click Start > Control Panel Select Administration Tools Select Data Sources (ODBC) Give the ODBC Connection a name and supply the information on how to connect to the data source 3.4.5 Database Procedures In this section we describe in detail the procedures and methodologies used in the development of the various Databases. 3.4.5.1 Creating a Database NOTE: This project contains a number of SQL Databases each replicating a system which exists within the CIE Group infrastructure. For example the Irish Rail Real-time system is a.net based application providing up to the minute train time data to the public via a page on the Irish Rail website. For the purpose of including this data in the form of a web service 29
making up part of the Ireland Transport API this.net Real-time application is replicated in the form of a SQL database. The following steps describe the process of creating the IR_RealTime database. 1. Select New database and give the new database a name Figure 7.0 Creating a Database 2. Add your tables by right-clicking in Tables and selecting New Table and using the designer view to create the required table structure Figure 8.0 Creating a Table 3. Create the Stored Procedure which will form the query to retrieve real-time data for a specified station Figure 9.0 SQL Server 2008 (Dewson, 2008) 30
3.4.5.1.1 ** LINQ to SQL LINQ is a component of the.net Framework which allows you to model your databases as objects within your application. To map your database to an application object: 1. Right click on your application name in the solution explorer 2. Select Add >> New Item 3. From the Installed Templates list select Data Figure 10.0 Adding a LINQ to SQL Class 4. Select LINQ to SQL Classes this will add a.dbml file to your project 5. From the Database Explorer tab connect to your database 6. Drag and drop the required tables / stored procedures onto the design surface of your.dbml file 7. You can now reference you database as an object from within your application (Rattz, 2010) This procedure was done for each database which replicates a CIE legacy system: IR_SeatRes; IR_Schedule; IR_Realtime; DB_Main; DB_Scheduler; DB_FaresEngiine; BE_Main; BE_Scheduler. See Appendix 5.2 for the complete SQL code 31
3.4.6 Mobile Application Technologies This section outlines the technologies used in the development of the Proof-of-Concept Android App, the purposr of this App is to demonstrate the potential use of the API 3.4.6.1. Eclipse IDE / Android Development Tools Eclipse is a multi-language Integrated Development Environment with an extensible plug-in system. Eclipse provides a Google-developed framework specifically for the development of Java based mobile Applications for the Google Android Smartphone which is a Linux based device making it incompatible with a.net based application. The Android Development Tools (ADT) plug-in is a Java based library developed by Google specifically for the development of Google Android mobile Applications, features such as GPS positioning as well as a variety of security features make it a popular choice for mobile application development. 3.4.6.1.1 Installation and Configuration of Eclipse IDE with Android Development Tools This section outlines the step by step process employed in the setup of our environment for the development of the Android App Step 1 Download Eclipse and Android Development Tools: 1. Download the Eclipse IDE Download the Eclipse IDE installation zip file (eclipse-java-helios-sr2-win32.zip) from the following location (http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/heli os/sr2/eclipse-java-helios-sr2-win32.zip); Unpack the zip file into your desired folder. Unzipping the file will create a sub-folder called eclipse which is where the IDE is now installed. 2. Download and install the Android SDK Download the Android SDK from the following location (http://developer.android.com/sdk/index.html); Extract the zip file into your desired folder. 32
3. Download and install the Android Development Tools (ADT) Plugin for Eclipse Installing the ADT Plugin o Run Eclipse; o Select Help >> Install New Software; Figure 11.0 Android Development Toolkit o Enter the following url for the Location (https://dl-ssl.google.com/android/eclipse/), click OK; o Select the checkbox next to Developer Tools and click Next; o Click Next and Finish; o Restart Eclipse. 4. Configuring the ADT Plugin 1. Run Eclipse; 2. Select Window >> Preferences; 3. Browse to the location of the installed Android SDK; Figure 12.0 Configuring the ADT 33
4. Click Apply and OK. Step 2 Setup an Android Virtual Device (AVD) using AVD Manager (Android Emulator) 1. An Android Virtual Device (AVD) is a device configuration for the Android emulator that allows the user to model different Android device configurations. The AVD Manager in Eclipse allows you to manage your AVD s Figure 13.0 Android Virtual Device 2. To create a new AVD firstly launch the AVD Manager from Eclipse by selecting Window >> Android SDK and AVD Manager, here you will see the list of existing AVDs 3. Select New Figure 14.0 Android Virtual Device 34
4. Enter the details for the new AVD a. Name b. Platform Target (e.g. Android 1.5, Android 1.6 etc ) c. An SD Card size d. A skin (HVGA is the default) e. Additional optional hardware features (e.g. touch screen support track ball support, camera support etc ) 5. The AVD has now been created and can be selected as the desired emulator when running your application 6. You can create any number of AVDs, for the purpose of testing the app developed as part of this project an AVD was created for every Android API level (see Android and AVD Manager screenshot above) 3.4.7 Mobile Application Procedures Development of the Android Mobile App This section outlines the step by step process employed in the development of the Android App 3.4.7.1 Eclipse Android Application Project Step 1 Create the Android Project 1. The next step in the development of the Android App is to create a new Android project. 2. Launch Eclipse 3. Select File >> New Project Figure 15.0 New Android Project 4. the New Project window select Android >> Android Project 5. Enter the details for the project including name, package name, Android Platform target and main Activity class name 35
Figure 16.0 New Android Project Step 2 Create App Activities Android Apps are made up of a series of Activities, an Activity is a component of the application which provides a screen through which the user can perform a function. An app is usually made up of multiple activities bound to each other. To create an Activity 1. Create a subclass of the Activity class which implements the callback methods the system calls as the Activity transitions between states for example oncreate() onstart() onpause() onstop() ondestroy() 2. Continue creating Activities for each screen required by the App 3.4.7.1.1 Proof of Concept: Development of an Irish Rail Taxi App As a proof of concept to demonstrate the possibilities of the API a number of sample Google Android App s were developed. 1. A basic app aimed at taxi drivers which provides information on the numbers of passengers arriving into the various train stations. This app works by making a request to the API for all stations and the numbers of passengers arriving into these stations. Code Segment 3.0 displays the code for the creation of the main android activity for this app, this activity contains a List populated by the JSON format response data from the Irish Rail Passenger numbers web service. 36
Code Segment 3.0 Method Implementation LINQ package nci.apidemo; import java.io.ioexception; import java.util.arraylist; import org.apache.http.httpresponse; import org.apache.http.parseexception; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.methods.httpget; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.util.entityutils; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import android.app.listactivity; import android.os.bundle; import android.widget.arrayadapter; import android.widget.listadapter; public class Main extends ListActivity { // Called when the Activity is first created @Override protected void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); // call the web service DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://10.0.2.2:80/IrelandTransportAPI/ITNService.svc/json/iePassengerNumbers"); HttpResponse response; ArrayList<String> list = new ArrayList<String>(); try { // parse the JSON response data and populate a list with the content response = client.execute(httpget); JSONObject rootobject = new JSONObject(EntityUtils.toString(response.getEntity())); JSONArray results = rootobject.getjsonarray("getiepassengernumbersjsonresult"); for (int i = 0; i < results.length() ; i ++){ JSONObject object = results.getjsonobject(i); String thestring = object.getstring("_stationname") + " : " + object.getstring("_passengernumbers"); list.add(thestring); catch (ClientProtocolException e1) { e1.printstacktrace(); catch (IOException e1) { e1.printstacktrace(); catch (ParseException e) { e.printstacktrace(); catch (JSONException e) { e.printstacktrace(); // display the list ListAdapter listadapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list); setlistadapter(listadapter); Figure 17.0 shows the main activity for the proof-of-concept Android App, this app consumes the Irish Rail Passenger Numbers web service and parses the response data into an Android List activity. 37
Figure 17.0 Basic Taxi App 2. A more advanced version of the previous app, this app provides the same information but rather than showing passenger numbers for all stations it uses the Android Development Tools plugin GPS features to locate the taxi and then request passenger numbers for the local stations only. This app works by firstly, making a request to the API for the nearest train stations to the taxi s location, this will involve a comparison being done between the taxi s longitude and latitude values as well as the longitude and latitude values of Irish rail stations, and this information is available from an existing Irish Rail system. Secondly, a request is made to the API which will return the numbers of passengers arriving into these stations. Figure 18.0 GPS Taxi App 3. An app which consumes the ierealtime web service to display realtime data for a specified station 38
Figure 19.0 - Realtime App These apps are simple in concept yet the benefits are clear as it will allow the taxi driver to make an informed choice with regard to maximising their potential customer numbers. This apps were developed in Java using the Eclipse IDE along with the Android Development Tools (ADT) plugin which is a library of Google-developed classes specific to the development of Android Apps. The reason for the choice of Java for the development of the apps is based on the fact that a Google Android device is built on a Linux based operating system and as such is incompatible with a.net based application but because the API services are requested via RESTful url requests they can easily be made from the java based Android application. (Consuming WCF Services with Android, 2010) 3.5 Testing Software Testing is an important stage in the Software Development Lifecycle, testing involves validating and verifying the input and output of the system to ensure it meets the requirements which initially determined its design and development and to ensure that it first and foremost works as expected. Traditionally, testing is initiated from the moment the coding phase is complete when the developer hands the system over to a dedicated testing team however in the course of the development of the Ireland Transport Network Web Service API we employed the newer model of test driven development which places an increased portion of the responsibility of testing in the hands of the developer to be implemented throughout the course of the development There are many different levels of testing which can be employed, as part of the test driven development process Unit Testing was carried out as each web service was created. Unit testing involves testing the application s individual components usually at a class level; unit testing alone cannot verify the overall functionality of the system but rather validates the individual building blocks which together make up the overall system. From the point of view of the API, the individual the individual classes which represent for example stations, routes etc. were tested by creating and validating each class individually. As well as the testing of these classes, high level unit testing was performed on each web service as they were developed and added to the API. This involved making a request against the web service and then validating the output whether JSON or XML against our expected results. 39
The next phase of our testing involved System Testing. System Testing is performed when the system is fully developed and integrated, System Testing is closely linked with the Functional Requirements of a system, it involves testing the system as a whole to ensure the requirements have been met. Our System Testing phase began when the API was complete from a development perspective and had been moved from running on the local Visual Studio Development Server to running on Internet Information server (IIS). The last phase of our testing involves User Acceptance Testing. Traditionally User acceptance Testing is performed by the customer to ensure the system meets their requirements. The Ireland Transport Network Web Service API is intended primarily for application developers wishing to make use of the data it exposes in various useful transport related applications. For this reason we performed our User Acceptance Testing from the perspective of such an application developer, this was done as part of the development of the proof-ofconcept Android App. (Graham Dorothy, Van Veenendal, Evans, & Black) 3.6 Graphical User Interface (GUI) Layout The public interface for the Ireland Transport Web Service API is in the form of a simple.net website, the purpose of this website is to act as a public portal aimed primarily at developers who are interested in making use of the API. Figure 20.0 Ireland Transport Network API Homepage The website gives a general overview of the API and the web services it comprises, it also provides sample feeds as well as sample response data and has a dedicated Developer area which provides technical information and sample code segments for requesting and implementing the API web services. 40
Figure 21.0 Ireland Transport Network API Feed Details The API Home website also contains a User Guide - See Appendix 5.2 In this report we have introduced the Ireland Transport Network Web Service API, we began by introducing the concept of an API, what the current stat-of-the-art is with regard to API s and how API s benefit the software development industry as a whole. We looked broadly at a wellknown API before focussing more specifically on Travel and Transport related API s on which we have modelled ours. We outlined the aims of the project and an overview of the technologies to be used. We then looked in detail at the System as a whole, we defined the Requirements, outlined the Design and Architecture and outlined in detail the technologies and methodologies used in the implementation of the API and the demonstrating Android App. We described the Testing methods employed throughout the development process and we introduced the Graphical User Interface or API Home website which provides a public portal for the API including developer specific detail on how to go about consuming a web service from an external application. The core functionality of the WCF Application we have created involves firstly, the querying of a legacy system to return a resultset; we then use this resultset to create a generic list of serialized objects, these objects are of a type specific to the web service being called, each web service has its associated serialized objects each of which is defined in the application. Serialized objects allow for the conversion of the object to a form which can be transmitted across a network in our case we employed the XML and JSON formats as we believed these to be the most popular data formats being delivered from today s API s 4.1 Milestones and Hurdles A number of significant milestones were achieved in the course of the development of the Ireland Transport Network Web Service API; the first milestone was the implementation of the first WCF Web Service, the API is fundamentally a library of WCF web services the successful implementation of the first service was a significant step in the overall development. The next milestone was successfully connecting to the SQL database from the WCF Application; we had made the decision to use the LINQ framework for database connection which claims to simplify the process of connecting to a data source from within an application, again 41
the API consists of a series of Web Services each of which makes a connection to a SQL database so successfully implementing the LINQ framework in the first web service was again a significant milestone. When the API was complete the next significant milestone was the creation of our first Android App and immediately after, the creation of our first Android App which successfully consumed a RESTful web service. In the course of achieving the milestones mentioned above, a number of hurdles needed to be overcome, firstly understanding the concepts behind the REST protocol required a significant amount of research, having read up on a number of current API s is was clear that the REST protocol is arguably the most used protocol for API development today, traditionally Microsoft Web Service applications would be developed using the SOAP framework so a little extra work was involved in understanding how to implement our API as a RESTful API. Another hurdle which needed to be overcome came about when attempting to consume a web service from the Ireland Transport Network API itself, the API was successfully running on IIS and was delivering the expected results when making a web service request from a browser, however despite the fact that we could successfully consume any number of public web services on the internet we could not connect to the Ireland Transport Network API, after some more research we discovered that this issue is specific to running the Android App on the emulator rather than an Android phone, there is a known issue with attempting to consume a web service which resides on machine hosting the emulator. After some research we discovered the emulator has a dedicated host loopback interface which resolves this issue. This issue is resolved by calling the web service using this host loopback ip address along with the correct port number on which the API is listening (10.0.2.2:80). 4.2 Future Prospects In the course of the research and also the development of the Ireland Transport Network API it has become clear that this application has definite commercialisation prospects. Clear evidence exists showing the demand for such services as well as the benefits by a company exposing their data in a structured raw format for the purpose of allowing it to be used in the development of a variety of web and mobile applications. This API will not only be of benefit to developers wishing to develop transport specific applications but also developers interested in the development of countless useful Mashup applications making use of the API. A Mashup is the term used to describe a web or mobile application which ties together data sourced from not one but a variety of APIs to produce a single product. This API could be used in a variety of these Mashup s, an example being a Tourist focussed mobile app which could tie together data from an API provided by the Irish Tourism Board along with the Ireland Transport API to deliver a useful app for tourists outlining for example What to see and how to get there type information. In conclusion we believe we have achieved our aim of producing a working model of a WCF Web Service API in that we have successfully exposed data from a series of SQL Databases replicating CIE Group companies legacy systems, this API exposes transport related information but the overall model, we believe could be applied to any company s architecture to expose their data in a structured way. 42
Objectives The objective of this project is to create an Ireland Transport System API as well as an application which demonstrates the API s functionality. Ireland Transport API The API will serve as a development platform for programmers wishing to build applications which provide information on Transport in Ireland, information such as: real-time travel information; route information; schedule information; station information. Mobile Application The purpose of the mobile application will be to demonstrate the functionality of the Ireland Transport API via a mobile information portal. Background The Evolution of Web Technologies As recently as 10 years ago, applications such as email or online chat would have been considered the most advanced applications in Web Technologies. Data driven web environments were only beginning to emerge. More recently however the web has not only evolved in terms of the technologies it offers to the end user but in effect has itself become a development platform, developers can now write applications on Facebook or on Google in the same way as they would have once written applications on Windows or on UNIX. Developers can do this by making use of the API s which have been developed by many of the industry s main players (Google, Facebook, Amazon, Yahoo) and made available in the form of a library of routines, tools and protocols for building software applications What is an API? Def n : An API or Application Programming Interface is an interface allowing communication between different software systems. An API makes a developer s job of creating an application easier by providing some of the building blocks necessary. The developer s job is to put the blocks together. Although APIs are designed for the needs of a developer by providing pathways into a systems data, they are ultimately beneficial to the end user as they provide an environment which promotes the development of an infinite number of useful end user focussed applications. The Ireland Transport System - The need for an API Currently the Ireland Transport System comprising Irish Rail and Dublin Bus provide information to the public on their own company websites in the form of web pages, RSS feeds as well as printed information. However this information is fragmented and comes in different formats. This project proposes to solve these problems by unifying the information into a common data source available centrally through the Ireland Transport System API. This API will serve as the central access point for application developers wishing to create transport related applications. 43
Technical Approach - API REST REST or REpresentational State Transfer is an architectural style governing the behaviour of distributed applications. The REST protocol defines a number of constraints and a system which conforms to these constraints is said to be RESTful. A RESTful API accepts requests from a client through a well-structured URL; the server processes the request and returns a response normally in XML or JSON format. XML XML or Extensible Markup Language is a universally accepted data format used primarily for the transfer of structured data. In the context of a Web Services API xml is a widely used format for accepting client requests as well as sending server responses. JSON JSON or JavaScript Object Notation is a lightweight human-readable data-transfer format. It is primarily used as a means of transferring data over a network. JSON is based on the JavaScript programming language but is considered language independent. JSON can be used as an alternative to XML. Approach Having researched a number of Web Service API s the technical approach I intend to take at this point is as follows. I intend to create a web services API which can be accessed through RESTful calls and which will accept requests in the form of a URL and format the responses in either XML or JSON. I intend to develop the Web Services API in the PHP programming language Technical Approach Mobile Application I intend to develop a mobile application to demonstrate the functionality of the Ireland Transport API; this application will be written in Java programming language making use of the Google Android API for mobile application development. Project Proposal The purpose of this document is to outline the scope of the project. Requirements Specification Research: In the course of my research I intend to speak to a number of mobile application developers who have created applications based on information provided by RSS feed on the Irish rail website. I intend to get feedback from them regarding what information would they have found useful in the development of their applications. Prototype A mid-term prototype presentation will show the progress of the project. Beta Version The Beta version of the project is effectively a pre-release of the finished project. Documentation The final project documentation will include the technical report as well as the project progress journal and the user manual. 44
Project Presentations The project presentation and project showcase will involve demonstrating the finished project. Consultations Jonathan Lambert I discussed the proposal at length with Jonathan. He helped me with defining the boundaries and scope of the project. In addition, we discussed breaking the project into its various functional components. Paul Stynes having discussed my project idea with Paul he suggested that it would be a good idea to develop an application which makes use of the API in order to demonstrate its functionality. Having had previous experience developing a mobile application using the Android API I decided that this would be a good addition to the scope of my project. 45
46
This section contains the Requirements Specification Document which was submitted earlier in the year. In the course of the development of the API some of the requirements changed slightly, this is reflected in the differences between what is outlined here compared to what is outlined in the requirements section of the main report. Requirements Specification (submitted November 2010) Physical Environment Requirements Requirement 1: WEBSERVICE API SERVER Description The physical setup of the Dublin Transport Web Service API server component should include Web Server for example Apache, configured to run PHP5.5 alongside SQL Server 2008. The API should be accessible remotely. Requirement 2: REQUESTING CLIENT Description In order to access a function which exists in another application the client application should be configured to send web service requests and accept web service responses this includes a reliable internet connection. Interface Requirements Requirement 1: EXTERNAL APPLICATION/MOBILE DEVICE The user interacts with the system via a client application for example an app residing on a Google Android mobile device. This client application makes RESTful calls to the Web Service API and the response from the API is in one of two formats XML or JSON specified in the client request. Requirement 2: SQL SERVER The API queries the Irish Rail/Dublin Bus database to get the Station and Route information. Requirement 3: FARES ENGINE API The Fares Engine is an internal application which accepts a request consisting of a journey, the application processes the journey details and returns the journey fare. Requirement 4: SEAT RESERVATION SYSTEM The Seat Reservation System is an internal application which manages the process of a customer booking a seat on a train, whether via the website, the booking office or the telesales systems. The information which the Dublin Transport Web Service API will obtain from the Seat Reservation System includes passenger numbers as well as schedule and journey planner information. Requirement 5: TRAIN OPERATING AND PERFORMANCE SYSTEM The Train Operating and Performance System is an internal application which manages the movements of trains around the Irish Rail network.. The Dublin Transport Web Service API will obtain Real-time information from this system Functional Requirements This section lists the functional requirements of the Dublin Transport Web Service API outlining the functions which the API will provide. 47
Requirement 1: STATION INFORMATION The system should provide details of a supplied station, details similar to what is currently available on the Irish Rail website. Information should include Station Name/Address/Phone number; GPS Co-ordinates; Routes Serviced; Opening Hours; Booking Office; Car park; Accessibility (Booking Office Loop system/platform access); Local Bus Stops and areas serviced by local buses. Description Irish Rail has a large number of train stations in and around the Dublin area. From the larger train stations e.g. Heuston Station and Connolly Station, both of which service the rest of Ireland, to much smaller local stations. Useful information which will be exposed via the Dublin Transport Web Service API include such things as station address and contact information, station GPS location, opening times, whether or not the station is staffed, booking office or ticket vending machine facilities as well as accessibility facilities including wheelchair ramps and loop systems for the hearing impaired. Activation The requesting mobile application makes a call to the Web Service API specifying the station for which information is being requested, the response returned to the requesting application includes all relevant station information Technical issues The request is made to the API through RESTful calls and the responses will be formatted in either XML or JSON. RISKS This requirement relies on there being a reliable internet connection Requirement 2: ROUTE INFORMATION The system shall provide details of a supplied route, information should include Stations serviced Bus connections Description Irish Rail and Dublin Bus have a number of services operating in the Dublin area, DART and suburban services as well as airport and port connection services. Information in relation to these routes will be available via the Dublin Transport Web Service API. Requirement Activation The requesting mobile application makes a call to the Web Service API specifying the route for which information is being requested; the response returned to the requesting application includes all relevant route information. 48
Technical issues The request is made to the API through RESTful calls and the responses will be formatted in either XML or JSON. RISKS This requirement relies on there being a reliable internet connection Requirement 3: SCHEDULE INFORMATION The system shall provide schedule information from Irish Rails timetable legacy system. Description Schedule information is by far the most requested information from the public website. The Dublin Transport Web Service API will provide schedule information for a journey station combination specified in the request. Activation The requesting mobile application makes a call to the Web Service API specifying the from/to station combination for which the schedule information is being requested, the response returned to the requesting application includes train times from the Irish Rail timetable legacy system. Technical issues The request is made to the API through RESTful calls and the responses will be formatted in either XML or JSON. RISKS This requirement relies on there being a reliable internet connection Requirement 4: REALTIME INFORMATION The system shall provide up to the minute real-time information for a specified station and for a specified train, this information comes from Irish Rails real-time system. Description Irish Rail maintains a real-time management system which manages all train movements as they happen. This information is processed and made available via the Irish rail website in the form of a real-time train positioning and schedule web page and also an RSS feed, this information will now be exposed via the Dublin Transport Web Service API enabling mobile application developers to create useful real-time applications. Activation 1. The requesting mobile application makes a call to the Web Service API specifying the station for which the real-time information is being requested, the response returned to the requesting application includes up to the minute train positioning and schedule information for all trains due into the specified station. 2. The requesting mobile application makes a call to the Web Service API specifying the train for which the realtime information is being requested, the response returned to the requesting application includes up to the minute train positioning and schedule information for the specified train. 3. Technical issues The request is made to the API through RESTful calls and the responses will be formatted in either XML or JSON. RISKS This requirement relies on there being a reliable internet connection 49
Requirement 5: PASSENGER NUMBERS The system shall provide information regarding the number of passengers arriving into the major stations in the city centre and also number of passengers arriving into a specified station. Description Irish Rail s Seat Reservation System which combines online reservations, booking office reservations and telesales reservations contains information with regard to numbers of passengers booked on trains arriving into a station. The Dublin Transport Web Service API will expose this information. Activation 1. All Stations: The requesting mobile application makes a call to the Web Service API requesting the passenger number information for all stations, the response returned to the requesting application contains total numbers of passengers arriving into each of the main stations within a specified timeframe. 2. Specific Station: The requesting mobile application makes a call to the Web Service API specifying the station for which the passenger number information is being requested, the response returned to the requesting application includes the passenger numbers on all trains arriving into the specified station within a specified timeframe. Technical issues The request is made to the API through RESTful calls and the responses will be formatted in either XML or JSON. RISKS This requirement relies on there being a reliable internet connection Requirement 6: JOURNEY PLANNER INFORMATION The system shall provide journey planner information for a combination of stations provided. Description The Journey Planner is part of the Seat Reservation System, it accepts a from/to station combination and returns a journey itinerary, this itinerary may include a single journey with schedule time or it may include a number of journey legs depending on the from/to station combination entered. Activation The requesting mobile application makes a call to the Web Service API specifying the from/to station combination for which the journey planner information is being requested, the response returned to the requesting application includes the journey itinerary along with scheduled times from the Irish Rail timetable legacy system. Technical issues The request is made to the API through RESTful calls and the responses will be formatted in either XML or JSON. RISKS This requirement relies on there being a reliable internet connection Requirement 7: FARE INFORMATION The system shall provide fare information for a journey provided. Description Irish Rail and Dublin Bus maintain a Fares Engine system which provides fare information for any journey on the network. This fare information will be made available via the Dublin Transport API 50
Activation The requesting mobile application makes a call to the Web Service API specifying the date of travel and train and train time for which the fare information is being requested, the response returned to the requesting application will provide the fare for the specified journey. Technical issues The request is made to the API through RESTful calls and the responses will be formatted in either XML or JSON. RISKS This requirement relies on there being a reliable internet connection Documentation Requirements Requirement 1: API USER GUIDE Description The system shall include an API Reference and Developer guide containing information on implementing an application using the Dublin Transport Web Service API; this will be made available online and will be aimed at mobile application developers. The mobile application shall include a user guide outlining how to best get the information required from the application. 51
4.1 API (C#) This section provides the code segments which comprise the WCF Application, the configuration file, the interface file and the implementation file as well as the various objects required by the system. The configuration file (web.config) describes is the main configuration file for the WCF Application, web.config is a xml based file and contains for example database connection strings <connectionstrings> <add name="ir_seatresconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=IR_SeatRes;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> <add name="ir_scheduleconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=IR_Schedule;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> <add name="ir_realtimeconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=IR_RealTime;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> <add name="db_mainconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=DB_Main;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> <add name="db_schedulerconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=DB_Scheduler;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> <add name="db_faresconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=DB_Fares;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> <add name="be_mainconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=BE_Main;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> <add name="be_schedulerconnectionstring" connectionstring="data Source=LINDA-PC\SQLEXPRESS;Initial Catalog=BE_Scheduler;User ID=API_USER;Password=apiuser" providername="system.data.sqlclient" /> </connectionstrings> web service Endpoint details (address, binding and contract) <services> <service name="irishtransportnetworkapi.itnservice" behaviorconfiguration="servicebehavior"> <endpoint address="" binding="webhttpbinding" contract="irishtransportnetworkapi.iitnservice" behaviorconfiguration="web"></endpoint> </service> </services> and Endpoint behaviour <behaviors> <servicebehaviors> <behavior name="servicebehavior"> <servicemetadata httpgetenabled="true"/> <servicedebug includeexceptiondetailinfaults="false"/> </behavior> </servicebehaviors> <endpointbehaviors> <behavior name="web"> <webhttp/> </behavior> </endpointbehaviors> </behaviors> The Interface file (IITNService.cs) defines the services which make up the API [ServiceContract] public interface IITNService { /// IRISH RAIL /// Stations /// XML format - Irish Rail Station Details /// <returns>a list of objiestation objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/iestations")] List<objIEStation> getiestationsxml(); 52
/// JSON format - Irish Rail Station Details /// <returns>a list of objiestation objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/iestations")] List<objIEStation> getiestationsjson(); /// Schedules /// XML format - Irish Rail Schedule Information /// <param name="origincode">the code of the Origin Station</param> /// <param name="destinationcode">the code of the Destination Station</param> /// <param name="schdate">the date of the required schedule</param> /// <returns>a list of objieschedule objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/ieschedule/{origincode/{destinationcode/{schdate")] List<objIESchedule> getieschedulexml(string origincode, string destinationcode, string schdate); /// JSON format - Irish Rail Schedule Information /// <param name="origincode">the code of the Origin Station</param> /// <param name="destinationcode">the code of the Destination Station</param> /// <param name="schdate">the date of the required schedule</param> /// <returns>a list of objieschedule objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/ieschedule/{origincode/{destinationcode/{schdate")] List<objIESchedule> getieschedulejson(string origincode, string destinationcode, string schdate); /// Realtime Data /// XML format - realtime information /// <param name="stncode">the station code for which realtime information is required</param> /// <returns>a list of objrealtime objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/ierealtime/{stncode")] List<objRealtime> getierealtimexml(string stncode); /// JSON format - realtime information /// <param name="stncode">the station code for which realtime information is required</param> /// <returns>a list of objrealtime objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/ierealtime/{stncode")] List<objRealtime> getierealtimejson(string stncode); // Delayed Trains /// XML format - Delayed Trains /// <returns>a list of objdelay objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/iedelays")] List<objDelay> getiedelaysxml(); /// JSON format - Delayed Trains /// <returns>a list of objdelay objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/iedelays")] List<objDelay> getiedelaysjson(); 53
// Passenger Numbers by (Dublin) Stations /// XML format - Passenger Numbers arriving into Dublin Stations /// <returns>a list of objiepassengernumbers objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/iepassengernumbers")] List<objIEPassengerNumbers> getiepassengernumbersxml(); /// JSON format - Passenger Numbers arriving into Dublin Stations /// <returns>a list of objiepassengernumbers objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/iepassengernumbers")] List<objIEPassengerNumbers> getiepassengernumbersjson(); //DUBLIN BUS // Routes /// XML format - Dublin Bus routes /// <returns>a list of objroute objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/dbroutes")] List<objRoute> getdbroutesxml(); /// XML format - Dublin Bus routes /// <returns>a list of objroute objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/dbroutes")] List<objRoute> getdbroutesjson(); /// Schedules /// XML format - Dublin Bus schedule information /// <param name="routenumber">the route number</param> /// <param name="schdate">the schedule date</param> /// <returns>a list of objschedule objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/dbschedule/{routenumber/{schdate")] List<objSchedule> getdbschedulexml(string routenumber, string schdate); /// JSON format - Dublin Bus schedule information /// <param name="routenumber">the route number</param> /// <param name="schdate">the schedule date</param> /// <returns>a list of objschedule objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/dbschedule/{routenumber/{schdate")] List<objSchedule> getdbschedulejson(string routenumber, string schdate); // Fares /// XML format - Dublin Bus fare information /// <returns>a list of objdbfare objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/dbfares")] List<objDBFare> getdbfaresxml(); 54
/// JSON format - Dublin Bus fare information /// <returns>a list of objdbfare objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/dbfares")] List<objDBFare> getdbfaresjson(); //BUS ÉIREANN /// XML format - Bus Éireann routes /// <returns>a list of objroute objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/beroutes")] List<objRoute> getberoutesxml(); /// JSON format - Bus Éireann routes /// <returns>a list of objroute objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/beroutes")] List<objRoute> getberoutesjson(); /// XML format - Bus Éireann schedule information /// <param name="routenumber">the route number</param> /// <param name="schdate">the schedule date</param> /// <returns>a list of objschedule objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/beschedule/{routenumber/{schdate")] List<objSchedule> getbeschedulexml(string routenumber, string schdate); /// JSON format - Bus Éireann schedule information /// <param name="routenumber">the route number</param> /// <param name="schdate">the schedule date</param> /// <returns>a list of objschedule objects</returns> [OperationContract] [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/beschedule/{routenumber/{schdate")] List<objSchedule> getbeschedulejson(string routenumber, string schdate); The Implementation file (ITNService.svc.cs) provides the implementation for each of the services defined in the interface file 1. Irish Rail Stations /* 1 - IE Stations */ /// Irish Rail Station Information /// <returns>a list of objiestation objects</returns> public List<objIEStation> getiestationsxml() { return getiestations(); /// Irish Rail Station Information /// <returns>a list of objiestation objects</returns> public List<objIEStation> getiestationsjson() { return getiestations(); /// Queries the IR_Realtime database to get a list of stations /// <returns>a list of objiestation objects</returns> public List<objIEStation> getiestations() { List<objIEStation> iestationdata = new List<objIEStation>(); var db_irrealtime = new IR_RealTimeDataContext(); 55
var stationdataquery = db_irrealtime.spgetstations(); foreach (var stationdata in stationdataquery) { objiestation mystation = new objiestation(stationdata.stationid, stationdata.stationdesc, stationdata.stationcode, (float)stationdata.longitudefloat, (float)stationdata.latitudefloat); iestationdata.add(mystation); return iestationdata; 2. Irish Rail Schedules /* 2 - Schedule Data */ /// Irish Rail Schedule Information /// <param name="origincode">the origin code</param> /// <param name="destinationcode">the destination code</param> /// <param name="scheduledate">the schedule date</param> /// <returns>a list of objieschedule objects</returns> public List<objIESchedule> getieschedulexml(string origincode, string destinationcode, string scheduledate) { return getieschedule(origincode, destinationcode, scheduledate); /// Irish Rail Schedule Information /// <param name="origincode">the origin code</param> /// <param name="destinationcode">the destination code</param> /// <param name="scheduledate">the schedule date</param> /// <returns>a list of objieschedule objects</returns> public List<objIESchedule> getieschedulejson(string origincode, string destinationcode, string scheduledate) { return getieschedule(origincode, destinationcode, scheduledate); /// Queries the IR_Schedule database to get schedule details for the origin/destination/date provided /// <param name="origincode">the origin code</param> /// <param name="destinationcode">the destination code</param> /// <param name="scheduledate">the schedule date</param> /// <returns>a list of objieschedule objects</returns> public List<objIESchedule> getieschedule(string origincode, string destinationcode, string scheduledate) { List<objIESchedule> iescheduledata = new List<objIESchedule>(); var db_irschedule = new IR_ScheduleDataContext(); var scheduledataquery = db_irschedule.spgetscheduleinformation(origincode, destinationcode, scheduledate); foreach (var scheduledata in scheduledataquery) { var strservice = scheduledata.train; objieschedule myscheduledata = new objieschedule(scheduledata.train, scheduledata.time); iescheduledata.add(myscheduledata); return iescheduledata; 3. Irish Rail Realtime /* 3 - Realtime Data */ /// Irish Rail Realtime Information /// <param name="stncode">station code for which realtime information is required</param> /// <returns>a list of objierealtime objects</returns> public List<objRealtime> getierealtimexml(string stncode) { return getierealtime(stncode); /// Irish Rail Realtime Information /// <param name="stncode">station code for which realtime information is required</param> /// <returns>a list of objierealtime objects</returns> public List<objRealtime> getierealtimejson(string stncode) { return getierealtime(stncode); /// Queries the IR_Realtime database to get up to the minute information on trains currently running /// <param name="stncode">station code for which realtime information is required</param> /// <returns>a list of objierealtime objects</returns> public List<objRealtime> getierealtime(string stncode) { List<objRealtime> ierealtimedata = new List<objRealtime>(); var db_irrealtime = new IR_RealTimeDataContext(); var realtimedataquery = db_irrealtime.spgetstationrealtimedata(stncode); foreach (var realtimedata in realtimedataquery) { var strjourney = realtimedata.origin + " - " + realtimedata.destination; objrealtime myrealtimedata = new objrealtime(strjourney, realtimedata.scharrival, realtimedata.exparrival); ierealtimedata.add(myrealtimedata); return ierealtimedata; 4. Irish Rail Delayed Trains 56
/* 4. Delayed Trains */ /// Irish Rail current delayed trains /// <returns>a list of objdelay objects</returns> public List<objDelay> getiedelaysxml() { return getiedelays(); /// Irish Rail current delayed trains /// <returns>a list of objdelay objects</returns> public List<objDelay> getiedelaysjson() { return getiedelays(); /// Queries the IR_Realtime database to get a list of trains which are currently delayed /// <returns>a list of objdelay objects</returns> public List<objDelay> getiedelays() { List<objDelay> iedelayedtrains = new List<objDelay>(); var db_irrealtime = new IR_RealTimeDataContext(); var delayedtrainsquery = db_irrealtime.spgetdelayedtrains(); foreach (var delayedtrainsdata in delayedtrainsquery) { var strjourney = delayedtrainsdata.trainorigin + " - " + delayedtrainsdata.traindestination; objdelay mydelayedtrain = new objdelay(strjourney, delayedtrainsdata.currentlocation, delayedtrainsdata.scheduledarrival, delayedtrainsdata.expectedarrival, delayedtrainsdata.delaymins); iedelayedtrains.add(mydelayedtrain); return iedelayedtrains; 5. Irish Rail Passenger Numbers /* 5. Passenger Numbers */ /// Irish Rail Passenger Numbers arriving into Dublin Stations /// <returns>a list of objiepassengernumbers objects</returns> public List<objIEPassengerNumbers> getiepassengernumbersxml() { return getiepassengernumbers(); /// Irish Rail Passenger Numbers arriving into Dublin Stations /// <returns>a list of objpassengernumbers objects</returns> public List<objIEPassengerNumbers> getiepassengernumbersjson() { return getiepassengernumbers(); /// Queries the IR_Schedule database to get booking information /// <returns>a list of objpassengernumbers objects</returns> public List<objIEPassengerNumbers> getiepassengernumbers() { List<objIEPassengerNumbers> iepassengernumbers = new List<objIEPassengerNumbers>(); var db_irschedule = new IR_ScheduleDataContext(); var passengernumbersquery = db_irschedule.spgetpassengernumbers(); foreach (var passengernumbers in passengernumbersquery) { objiepassengernumbers mypassengernumbers = new objiepassengernumbers(passengernumbers.stationname, passengernumbers.numpassengersarriving); iepassengernumbers.add(mypassengernumbers); return iepassengernumbers; 6. Dublin Bus Routes /* 1 - DB Routes */ /// Dublin Bus Route information /// <returns>a list of objroute objects</returns> public List<objRoute> getdbroutesxml() { return getdbroutes(); /// Dublin Bus Route information /// <returns>a list of objroute objects</returns> public List<objRoute> getdbroutesjson() { return getdbroutes(); /// Queries the DB_Main database to get a list of stations /// <returns>a list of objroute objects</returns> public List<objRoute> getdbroutes() { List<objRoute> dbroutes = new List<objRoute>(); var db_dbmain = new DB_MainDataContext(); 57
var dbroutesquery = db_dbmain.spdb_getroutes(); foreach (var route in dbroutesquery) { objroute myroute = new objroute(route.dbroutenumber, route.dbroutedescription); dbroutes.add(myroute); return dbroutes; 7. Dublin Bus Schedules /* 2 - Schedules */ /// Dublin Bus Schedule Information /// <returns>a list of objschedule objects</returns> public List<objSchedule> getdbschedulexml(string routenumber, string schdate) { return getdbschedule(routenumber, schdate); /// Dublin Bus Schedule Information /// <returns> A list of objschedule objects </returns> public List<objSchedule> getdbschedulejson(string routenumber, string schdate) { return getdbschedule(routenumber, schdate); /// Queries the DB_Scheduler database for Dublin Bus Schedule information /// <param name="routenumber">the route for which the schedule is required</param> /// <param name="schdate">the date for which the schedule is required</param> /// <returns>a list of objschedule objects</returns> public List<objSchedule> getdbschedule(string routenumber, string schdate) { List<objSchedule> dbschedule = new List<objSchedule>(); var db_dbschedule = new DB_SchedulerDataContext(); var dbschedulerquery = db_dbschedule.spgetdbscheduleinformation(routenumber, schdate); foreach (var schedule in dbschedulerquery) { objschedule myschedule = new objschedule(schedule.scheduleroute, schedule.journey, schedule.scheduletime); dbschedule.add(myschedule); return dbschedule; 8. Dublin Bus Fares /* 3 - Fares */ /// Dublin Bus Fare information /// <returns>a list of objdbfare objects</returns> public List<objDBFare> getdbfaresxml() { return getdbfares(); /// Dublin Bus Fare information /// <returns>a list of objdbfare objects</returns> public List<objDBFare> getdbfaresjson() { return getdbfares(); /// Queries the DB_Fares database for fare information based on the number of stages being travelled /// <returns>a list of objdbfare objects</returns> public List<objDBFare> getdbfares() { List<objDBFare> dbfaredata = new List<objDBFare>(); var db_dbfares = new DB_FaresDataContext(); var faresquery = db_dbfares.spdb_getfares(); foreach (var faredata in faresquery) { objdbfare myfare = new objdbfare(faredata.dbfare, faredata.dbfaredescription); dbfaredata.add(myfare); return dbfaredata; 9. Bus Éireann Routes /* 1 BE Routes */ /// Bus Eireann Route Information /// <returns>a list of objroute objects</returns> public List<objRoute> getberoutesxml() { return getberoutes(); /// Bus Eireann Route Information /// <returns>a list of objroute objects</returns> public List<objRoute> getberoutesjson() { return getberoutes(); 58
/// Queries the BE_Main database for Bus Eireann route information /// <returns>a list of objroute objects</returns> public List<objRoute> getberoutes() { List<objRoute> beroutes = new List<objRoute>(); var db_bemain = new BE_MainDataContext(); var beroutesquery = db_bemain.spbe_getroutes(); foreach (var route in beroutesquery) { objroute myroute = new objroute(route.beroutenumber, route.beroutedescription); beroutes.add(myroute); return beroutes; 10. Bus Éireann Schedules /* 2 - Schedules */ /// Bus Eireann Schedule information /// <returns>a list of objschedule objects</returns> public List<objSchedule> getbeschedulexml(string routenumber, string schdate) { return getbeschedule(routenumber, schdate); /// Bus Eireann Schedule information /// <returns>a list of objschedule objects</returns> public List<objSchedule> getbeschedulejson(string routenumber, string schdate) { return getbeschedule(routenumber, schdate); /// Queries the DB_Scheduler database for Bus Eireann Schedule information /// <param name="routenumber">the route for which the schedule is required</param> /// <param name="schdate">the date for which the schedule is required</param> /// <returns>a list of objschedule objects</returns> public List<objSchedule> getbeschedule(string routenumber, string schdate) { List<objSchedule> beschedule = new List<objSchedule>(); var db_beschedule = new BE_SchedulerDataContext(); var dbschedulerquery = db_beschedule.spgetbescheduleinformation(routenumber, schdate); foreach (var schedule in dbschedulerquery) { objschedule myschedule = new objschedule(schedule.scheduleroute, schedule.journey, schedule.scheduletime); beschedule.add(myschedule); return beschedule; A sample of a database model language (.dbml) file, this file represents the LINQ to SQL functionality modelling a database as an object in the WCF Application. NOTE these classes are auto generated when a database is added to the project using the LINQ to SQL method outlined above. This is a sample of the DB_Scheduler.dbml class which models the DB_Scheduler database. namespace IrishTransportNetworkAPI { using System.Data.Linq; using System.Data.Linq.Mapping; using System.Data; using System.Collections.Generic; using System.Reflection; using System.Linq; using System.Linq.Expressions; using System.ComponentModel; using System; [global::system.data.linq.mapping.databaseattribute(name="db_scheduler")] public partial class DB_SchedulerDataContext : System.Data.Linq.DataContext{ private static System.Data.Linq.Mapping.MappingSource mappingsource = new AttributeMappingSource(); #region Extensibility Method Definitions partial void OnCreated(); #endregion public DB_SchedulerDataContext() : base(global::system.configuration.configurationmanager. ConnectionStrings["DB_SchedulerConnectionString"].ConnectionString, mappingsource){ OnCreated(); public DB_SchedulerDataContext(string connection) : base(connection, mappingsource){ OnCreated(); public DB_SchedulerDataContext(System.Data.IDbConnection connection) : base(connection, mappingsource) { OnCreated(); 59 public DB_SchedulerDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingsource) :
OnCreated(); base(connection, mappingsource){ public DB_SchedulerDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingsource) : base(connection, mappingsource){ OnCreated(); [global::system.data.linq.mapping.functionattribute(name="dbo.spgetdbscheduleinformation")] public ISingleResult<spGetDBScheduleInformationResult> spgetdbscheduleinformation ([global::system.data.linq.mapping.parameterattribute(dbtype="varchar(5)")] string route, [global::system.data.linq.mapping.parameterattribute(dbtype="datetime")] System.Nullable<System.DateTime> scheduledate){ IExecuteResult result = this.executemethodcall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), route, scheduledate); return ((ISingleResult<spGetDBScheduleInformationResult>)(result.ReturnValue)); public partial class spgetdbscheduleinformationresult{ private string _scheduleroute; private string _journey; private string _scheduletime; public spgetdbscheduleiformationresult() { [global::system.data.linq.mapping.columnattribute(storage="_scheduleroute", DbType="VarChar(5)")] public string scheduleroute { get{ return this._scheduleroute; set{ if ((this._scheduleroute!= value)){ this._scheduleroute = value; [global::system.data.linq.mapping.columnattribute(storage="_journey", DbType="VarChar(404)")] public string journey{ get{ return this._journey; set{ if ((this._journey!= value)){ this._journey = value; [global::system.data.linq.mapping.columnattribute(storage="_scheduletime", DbType="VarChar(30)")] public string scheduletime { get{ return this._scheduletime; set{ if ((this._scheduletime!= value)){ this._scheduletime = value; A variety of serialized classes which define the objects from which the web service responses are generates objiestation is a station object representing an Irish Rail station, created in the getiestations() service implementation method using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { /// The objiestation object represents an Irish Rail train station [Serializable] public class objiestation { /// A unique station ID number private int _stationid; /// The station id - get and set methods public int stationid { 60
get { return _stationid; set { _stationid = value; /// A description of the station private string _stationdescription; /// The station description - get and set methods public string stationdescription { get { return _stationdescription; set { _stationdescription = value; /// A 5 digit station code private string _stationcode; /// The station code - get and set methods public string stationcode { get { return _stationcode; set { _stationcode = value; /// The GPS longitude of the station private float _stationlongitude; /// The station longitude - get and set methods public float stationlongitude { get { return _stationlongitude; set { _stationlongitude = value; /// The GPS latitude of the station private float _stationlatitude; /// The station latitude - get and set methods public float stationlatitude { get { return _stationlatitude; set { _stationlatitude = value; /// The constructor sets the station id, station description, station code, station longitude and station latitude values /// <param name="stationid">a unique station ID number</param> /// <param name="stationdescription">a description of the station</param> /// <param name="stationcode">a 5 digit station code</param> /// <param name="stationlongitude">the GPS longitude of the station</param> /// <param name="stationlatitude">the GPS latitude of the station</param> public objiestation(int stationid, string stationdescription, string stationcode, float stationlongitude, float stationlatitude) { this._stationid = stationid; this._stationdescription = stationdescription; this._stationcode = stationcode; this._stationlongitude = stationlongitude; this._stationlatitude = stationlatitude; objieschedule is a schedule object representing a train time for a specified train journey for a specified date, created in the getieschedule() service implementation method using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { /// The objieschedule object represents an individual train service [Serializable] public class objieschedule { /// The service - traincode, origin and destination private string _service; 61
/// The train service - get and set methods public string service { get { return _service; set { _service = value; /// The time of the train service private string _scheduletime; /// The scheduletime - get and set methods public string scheduletime { get { return _scheduletime; set { _scheduletime = value; /// The constructor sets the service and scheduletime values /// <param name="service">the service - traincode, origin and destination</param> /// <param name="scheduletime">the time of the train service</param> public objieschedule(string service, string scheduletime) { this._service = service; this._scheduletime = scheduletime; 62 objierealtime is a realtime object representing a realtime record for a specified station, created in the getierealtime() service implementation method using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { /// The objierealtime object represents a train with its up to the minute realtime data [Serializable] public class objierealtime { /// The train journey - origin to destination private string _journey; /// The train journey - get and set methods public string journey { get { return _journey; set { _journey = value; /// The arrival time as outlined in the schedule private string _scheduledarrivaltime; /// The scheduledarrivaltime - get and set methods public string scheduledarrivaltime{ get { return _scheduledarrivaltime; set { _scheduledarrivaltime = value; /// The arrival time based on the current position of the train, taking delays into consideration private string _expectedarrivaltime; /// The expectedarrivaltime - get and set methods public string expectedarrivaltime{ get { return _expectedarrivaltime; set { _expectedarrivaltime = value; /// The constructor sets the journey, scheduledarrival and expectedarrival values /// <param name="journey">the train journey - origin to destination</param> /// <param name="scheduledarrivaltime">the arrival time as outlined in the schedule </param> /// <param name="expectedarrivaltime">the arrival time based on the current position of the train, taking delays into consideration</param> public objierealtime(string journey, string scheduledarrivaltime, string expectedarrivaltime) { this._journey = journey; this._scheduledarrivaltime = scheduledarrivaltime; this._expectedarrivaltime = expectedarrivaltime;
63 objiedelay is a delay object representing a currently delayed train, created in the getiedelays() service implementation method using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { /// The objiedelay object represents a train which is currently running behind schedule [Serializable] public class objiedelay { /// The delayed train journey - origin to destination private string _journey; /// The delayed train journey - get and set methods public string journey { get { return _journey; set { _journey = value; /// The delayed train's current location private string _currentlocation; /// The delayed train s current location - get and set methods public string currentlocation { get { return _currentlocation; set { _currentlocation = value; /// The arrival time as outlined in the schedule private string _scheduledarrivaltime; /// The delayed train's scheduledarrivaltime - get and set methods public string scheduledarrivaltime{ get { return _scheduledarrivaltime; set { _scheduledarrivaltime = value; /// The arrival time based on the current position of the train, taking delays into consideration private string _expectedarrivaltime; /// The delayed train's expectedarrivaltime - get and set methods public string expectedarrivaltime{ get { return _expectedarrivaltime; set { _expectedarrivaltime = value; /// The number of minutes behind schedule that the train is currently running private string _delayminutes; /// The delayminutes - get and set methods public string delayminutes { get { return _delayminutes; set { _delayminutes = value; /// The constructor sets the journey, currentlocation, scheduledarrivaltime, expectedarrivaltime and delayminutes values /// <param name="journey">the train journey - origin to destination</param> /// <param name="currentlocation">the trains current location</param> /// <param name="scheduledarrivaltime">the arrival time as outlined in the schedule </param> /// <param name="expectedarrivaltime">the arrival time based on the current position of the train, taking delays into consideration</param> /// <param name="delayminutes">the number of minutes behind schedule that the train is currently running</param> public objiedelay(string journey, string currentlocation, string scheduledarrivaltime, string expectedarrivaltime, string delayminutes) { this._journey = journey; this._currentlocation = currentlocation; this._scheduledarrivaltime = scheduledarrivaltime; this._expectedarrivaltime = expectedarrivaltime; this._delayminutes = delayminutes;
objiepassengernumbers is a passenger numbers object representing a numbers of passengers arriving into Dublin train stations within the next 2 hours, created in the getiepassengernumbers() service implementation method using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { [Serializable] public class objiepassengernumbers { /// The station name private string _stationname; /// The station name - get and set methods public string stationname { get { return _stationname; set { _stationname = value; /// A number of passengers private string _passengernumbers; /// The number of passengers - get and set methods public string passengernumbers { get { return _passengernumbers; set { _passengernumbers = value; /// The constructor sets the station name and passenger numbers values /// <param name="stationname">the station name</param> /// <param name="passengernumbers">a number of passengers</param> public objiepassengernumbers(string stationname, string passengernumbers) { this._stationname = stationname; this._passengernumbers = passengernumbers; objroute is a route object representing a Dublin Bus or Bus Éireann bus route, created in the getdbroutes() and getberoutes() service implementation methods using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { /// The objroute object represents an Irish Rail/Bus Éireann/Dublin Bus route with a route number and a description [Serializable] public class objroute { /// The route number private string _route; /// The route number - get and set methods public string route { get { return _route; set { _route = value; /// A description of the route private string _routedescription; /// The route description - get and set methods public string routedescription { get { return _routedescription; set { _routedescription = value; 64 /// The constructor sets the route number and the route description values
/// <param name="route">the route number</param> /// <param name="routedescription">a description of the route</param> public objroute(string route, string routedescription) { this._route = route; this._routedescription = routedescription; objdbfare is a fare object representing a Dublin Bus fare, created in the getdbfares () service implementation method using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { /// The objdbfare object represents a Dublin Bus fare [Serializable] public class objdbfare { /// The fare value private string _fare; /// The fare value - get and set methods public string fare { get { return _fare; set { _fare = value; /// A description of the fare private string _faredescription; /// The fare description - get and set methods public string faredescription { get { return _faredescription; set { _faredescription = value; /// The constructor sets the fare and faredescription values /// <param name="fare">the fare value</param> /// <param name="faredescription">a description of the fare</param> public objdbfare(string fare, string faredescription) { this._fare = fare; this._faredescription = faredescription; objschedule is a schedule object representing a Dublin Bus or Bus Éireann bus time for a specified bus route for a specified date, created in the getdbschedule() and getbeschedule() service implementation methods using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace IrishTransportNetworkAPI { /// The objschedule object represents an individual Dublin Bus or Bus Eireann service [Serializable] public class objschedule { /// The route private string _route; /// The bus route - get and set methods public string route { get { return _route; set { _route = value; /// The journey private string _journey; /// The bus journey - get and set methods public string journey { 65
get { return _journey; set { _journey = value; /// The time of the train service private string _scheduletime; /// The scheduletime - get and set methods public string scheduletime { get { return _scheduletime; set { _scheduletime = value; /// The constructor sets the route, journey and scheduletime values /// <param name="route">the route</param> /// <param name="journey">the journey - origin and destination</param> /// <param name="scheduletime">the time of the bus service</param> public objschedule(string route, string journey, string scheduletime) { this._route = route; this._journey = journey; this._scheduletime = scheduletime; 4.2 Database (SQL) This section provides the SQL code segments which comprise the various queries on the databases which replicate CIE company systems. Each of the Ireland Transport Network API web services query a SQL database to obtain the data to be exposed. 1. Irish Rail Stations queries the tbl_rtstations table in the IR_Realtime database which contains station details. -- ============================================= -- Author: -- Create date: 6th Feb 2011 -- Description: Returns Station Information -- ============================================= PROCEDURE [dbo].[spgetstations] BEGIN END SELECT stationid, stationcode, stationdesc, convert(float,longitude) as longitudefloat, longitude, convert(float,latitude) as latitudefloat, latitude FROM tbl_rtstations 2. Irish Rail Schedule queries the IR_Schedule database for the schedule details for a specified journey on a specified date -- ============================================= -- Author: -- Create date: 8 Feb 2011 -- Description: Returns the Schedule for a Journey -- for a particular date -- ============================================= PROCEDURE [dbo].[spgetscheduleinformation] @origin varchar(5), @destination varchar(5), @scheduledate varchar(10) BEGIN SELECT --scheduleid, CONVERT(varchar,trainDate,106) as 'Date', traincode + ' - ' + dbo.stationnamebycode(trainorigin) + ' TO ' + dbo.stationnamebycode(traindestination) as Train, convert(varchar,scheduleddeparture,108) as 'Time' from tbl_trainschedule where traindate = @scheduledate and trainorigin = @origin and traindestination = @destination and locationtype = 'O' -- only departure time of the Origin order by scheduleddeparture END 66
3. Irish Rail Realtime information queries the IR_RealTime database for up to the minute details on running trains, this is a substantially more complex query as the system which manages the train movements is somewhat more complex. The system works by processing movements, a movement is a text file which contains information on the current position of a train, the information in the text files are used to update the information in the tbl_rttraintimetable table which contains a record for each stop on a train journey, as the train progresses on its journey the movement text files are processed and the records for each stop are updated with arrival and departure information, this results in an up to the minute train positioning system. This query combines information from this tbl_rttraintimetable table as well as a headers table which contains a header record for each train. This query takes as a parameter the station for which realtime information is required; it combines 3 sub queries Trains which are en route and will pass through the specified station Trains which have yet to leave the origin where the origin is the specified station and Trains which have yet to leave the origin where the specified station is a stop on the journey -- ============================================= -- Author: -- Create date: 1st December 2010 -- Description: Gets up to the minute data for -- trains departing from a specified station -- in the next hour -- ============================================= PROCEDURE [dbo].[spgetstationrealtimedata] @stationcode VARCHAR(5) BEGIN -- use the station code to get the station full name DECLARE @StationName VARCHAR(100) SELECT @StationName = dbo.[stationnamebycode](@stationcode) -- set a flag on/off to specify if the station is a DART station DECLARE @dart BIT SELECT @dart = dartstation FROM dbo.tbl_rtstations WHERE stationcode = @stationcode -- creat a temporary table to hold the data DECLARE @tmprealtimedata TABLE( id INT IDENTITY(1, 1) NOT NULL, code VARCHAR(5), traindate DATETIME, origin VARCHAR(50), origintime DATETIME, destination VARCHAR(50), destinationtime DATETIME, trainstatus VARCHAR(25), lastlocation VARCHAR(75), late INT, nextstop VARCHAR(50), exparrival datetime, expdepart DATETIME, scharrival DATETIME, schdepart DATETIME, direction VARCHAR(3), dart BIT ) INSERT INTO @tmprealtimedata( code, traindate, origin, origintime, destination, destinationtime, trainstatus, lastlocation, late, nextstop, exparrival, expdepart, scharrival, schdepart, direction, dart ) -- 1. TRAINS THAT ARE EN ROUTE AND WILL BE ARRIVING IN SPECIFIED STATION SELECT tbl_rttrainheaders.traincode, tbl_rttrainheaders.traindate, dbo.stationnamebycode(tbl_rttrainheaders.trainorigin), tbl_rttrainheaders.trainorigintime, dbo.stationnamebycode(tbl_rttrainheaders.traindestination), tbl_rttrainheaders.traindestinationtime, 'En Route', 67
FROM CASE tbl_rttrainheaders.lastlocationtype WHEN 'D' THEN 'Departed ' ELSE 'Arrived ' END + dbo.stationnamebycode(tbl_rttrainheaders.lastlocation), tbl_rttrainheaders.difference / 60, dbo.stationnamebycode(tbl_rttrainheaders.nextlocation), tbl_rttraintimetable.expectedarrival, tbl_rttraintimetable.[expecteddeparture], [tbl_rttraintimetable].[scheduledarrival], [tbl_rttraintimetable].[scheduleddeparture], ISNULL(dbo.tbl_rtTrainHeaders.direction, 'X'), @dart tbl_rttrainheaders INNER JOIN tbl_rttraintimetable ON tbl_rttrainheaders.traincode = tbl_rttraintimetable.traincode AND tbl_rttrainheaders.traindate = tbl_rttraintimetable.traindate WHERE tbl_rttrainheaders.trainstatus = 'R' -- trains that are in running AND ( tbl_rttraintimetable.expectedarrival > '5 Feb 2011' ) -- todays train AND ( tbl_rttraintimetable.locationcode = @stationcode ) -- there is a record in tbl_traintimetable for the selected location AND SUBSTRING([tbl_rtTrainHeaders].[trainCode], 1, 1) IN ('A', 'B', 'D', 'P', 'E' ) -- passenger trains union -- TRAINS NOT YET RUNNING - WHERE THE SPECIFIED STATION IS PART OF THE JOURNEY SELECT tbl_rttrainheaders.traincode, tbl_rttrainheaders.traindate, dbo.stationnamebycode(tbl_rttrainheaders.trainorigin), tbl_rttrainheaders.trainorigintime, dbo.stationnamebycode(tbl_rttrainheaders.traindestination), tbl_rttrainheaders.traindestinationtime, 'No Information', ' ', 0, ' ', tbl_rttraintimetable.[scheduledarrival], tbl_rttraintimetable.[scheduleddeparture], [tbl_rttraintimetable].[scheduledarrival], [tbl_rttraintimetable].[scheduleddeparture], ISNULL(dbo.tbl_rtTrainHeaders.direction, 'X'), @dart FROM tbl_rttrainheaders INNER JOIN tbl_rttraintimetable ON tbl_rttrainheaders.traincode = tbl_rttraintimetable.traincode AND tbl_rttrainheaders.traindate = tbl_rttraintimetable.traindate WHERE tbl_rttrainheaders.trainstatus = 'N' -- trains not in running yet AND ( tbl_rttraintimetable.scheduledarrival BETWEEN '5 Feb 2011' and '6 Feb 2011') -- AND DATEADD(hour, 1, GETDATE()) ) -- due to arrive in the next hour AND ( tbl_rttraintimetable.locationcode = @stationcode ) -- int the selected station AND SUBSTRING([tbl_rtTrainHeaders].[trainCode], 1, 1) IN ('A', 'B', 'D', 'P', 'E' ) -- passenger trains union -- TRAINS NOT YET RUNNING - WHERE THE SPECIFIED STATION IS THE ORIGIN SELECT tbl_rttrainheaders.traincode, tbl_rttrainheaders.traindate, dbo.stationnamebycode(tbl_rttrainheaders.trainorigin), tbl_rttrainheaders.trainorigintime, dbo.stationnamebycode(tbl_rttrainheaders.traindestination), tbl_rttrainheaders.traindestinationtime, 'No Information', ' ', 0, ' ', tbl_rttraintimetable.[scheduledarrival], tbl_rttraintimetable.[scheduleddeparture], [tbl_rttraintimetable].[scheduledarrival], [tbl_rttraintimetable].[scheduleddeparture], ISNULL(dbo.tbl_rtTrainHeaders.direction, 'X'), @dart FROM tbl_rttrainheaders INNER JOIN tbl_rttraintimetable ON tbl_rttrainheaders.traincode = tbl_rttraintimetable.traincode AND tbl_rttrainheaders.traindate = tbl_rttraintimetable.traindate WHERE tbl_rttrainheaders.trainstatus = 'N' -- trains not in running yet AND ( tbl_rttraintimetable.scheduledarrival = '01 Jan 1900' ) -- where the Origin... (01 Jan 1900 is the ScheduledArrival for the Origin) AND ( tbl_rttraintimetable.locationcode = @stationcode ) --... is the selected station AND SUBSTRING([tbl_rtTrainHeaders].[trainCode], 1, 1) IN ('A', 'B', 'D', 'P', 'E' ) -- passenger train AND [dbo].[tbl_rttrainheaders].[trainorigintime] between '5 Feb 2011' and '6 Feb 2011' UPDATE @tmprealtimedata SET expdepart = schdepart WHERE expdepart < schdepart -- select the required fields from the @tmprealtimedata table SELECT GETDATE() AS servertime, code, @stationname AS StationFullName, @stationcode AS StationCode, CONVERT(VARCHAR, GETDATE(), 108) AS QueryTime, CONVERT(VARCHAR(11), traindate, 113) as traindate, origin, CONVERT(VARCHAR(5), origintime, 108) AS origintime, destination, CONVERT(VARCHAR(5), destinationtime, 108) AS destinationtime, 68
END trainstatus, lastlocation, late, nextstop, ISNULL(CONVERT(VARCHAR(5), exparrival, 108), 0) AS exparrival, ISNULL(CONVERT(VARCHAR(5), expdepart, 108), 0) AS expdepart, ISNULL(CONVERT(VARCHAR(5), scharrival, 108), 0) AS scharrival, ISNULL(CONVERT(VARCHAR(5), schdepart, 108), 0) AS schdepart, DATEDIFF(mi, GETDATE(), exparrival) AS duein, DATEDIFF(mi, scharrival, exparrival) AS late, direction, dart FROM @tmprealtimedata ORDER BY exparrival 4. Irish Rail Delays queries the IR_Realtime database to get current delayed trains -- ============================================= -- Author: -- Create date: 10 Feb 2010 -- Description: Returns current delayed trains -- ============================================= PROCEDURE [dbo].[spgetdelayedtrains] BEGIN SELECT tbl_rttrainheaders.traincode, dbo.stationnamebycode(tbl_rttrainheaders.trainorigin) AS trainorigin, dbo.stationnamebycode(tbl_rttrainheaders.traindestination) AS traindestination, dbo.stationnamebycode(tbl_rttrainheaders.lastlocation) AS currentlocation, CONVERT(VARCHAR,scheduledArrival,108) AS scheduledarrival, CONVERT(VARCHAR,expectedArrival, 108) AS expectedarrival, CONVERT(VARCHAR,DATEDIFF(MINUTE, scheduledarrival,expectedarrival)) AS delaymins FROM tbl_rttraintimetable, tbl_rttrainheaders WHERE tbl_rttrainheaders.traincode = tbl_rttraintimetable.traincode AND tbl_rttrainheaders.traindate = tbl_rttraintimetable.traindate AND DATEDIFF(MINUTE, scheduledarrival,expectedarrival) > 0 -- where there is a difference between scheduled and expected arrival times AND tbl_rttraintimetable.locationtype = 'D' -- ensures one record per delayed train ORDER BY DATEDIFF(MINUTE, scheduledarrival,expectedarrival) END 5. Irish Rail Passenger Numbers queries the IR_Schedule database to get the number of passengers arriving into Dublin train stations in the next 2 hours -- ============================================= -- Author: -- Create date: 10 Feb 2011 -- Description: Returns the number of passengers -- arriving into Dublin Train stations -- (Heuston and Connolly) in the next -- 2 hours -- ============================================= PROCEDURE [dbo].[spgetpassengernumbers] BEGIN SELECT dbo.stationnamebycode(bookingdestination) AS stationname, CONVERT(VARCHAR,COUNT(bookingName)) AS numpassengersarriving FROM tbl_bookings WHERE bookingdestination IN ('CNLLY','HSTON') -- only main Dublin stations AND bookingtraindate = CONVERT(DATETIME, CONVERT(CHAR, GETDATE(), 103), 103) AND bookingdestinationarrivaltime > GETDATE() AND bookingdestinationarrivaltime < DATEADD(MINUTE,120,GETDATE()) -- where arrival time is in the next 2 hours GROUP BY bookingdestination END 6. Dublin Bus Routes queries the DB_Main database returning a list of Dublin Bus routes -- ============================================= -- Author: -- Create date: 28th October 2010 -- Description: Returns a list of all Dublin Bus -- routes -- ============================================= PROCEDURE [dbo].[spdb_getroutes] BEGIN END 7. Dublin Bus Schedule SET NOCOUNT ON; SELECT * FROM tbl_dbroutes -- ============================================= -- Author: -- Create date: 10 Mar 2011 -- Description: Returns the schedule for a specified -- route on a specified date -- ============================================= PROCEDURE [dbo].[spgetdbscheduleinformation] @route varchar(5), @scheduledate datetime 69
BEGIN SET NOCOUNT ON; SELECT scheduleroute, scheduleorigin + ' TO ' + scheduledestination as journey, convert(varchar,scheduletime,108) as scheduletime FROM tbl_busschedule WHERE scheduleroute = @route AND scheduledate = @scheduledate AND schedulelocationtype = 'O' ORDER BY scheduletime END 8. Dublin Bus Fares queries the DB_Fares database returning fare data for Dublin Bus journeys -- ============================================= -- Author: -- Create date: 9 Feb 2011 -- Description: Returns Fare information for -- for Dublin Bus Journeys -- ============================================= PROCEDURE [dbo].[spdb_getfares] BEGIN SELECT CONVERT(VARCHAR,dbFare) AS dbfare, dbfaredescription FROM tbl_dbfares END 9. Bus Éireann Routes queries the BE_Main database returning a list of Bus Éireann routes -- ============================================= -- Author: -- Create date: 10 March 2011 -- Description: Returns a list of Bus Éireann -- routes -- ============================================= PROCEDURE [dbo].[spbe_getroutes] BEGIN SELECT * FROM tbl_beroutes END 10. Bus Éireann Schedule -- ============================================= -- Author: -- Create date: 10 March 2011 -- Description: Returns a list of Bus Éireann -- routes -- ============================================= PROCEDURE [dbo].[spgetbescheduleinformation] @route varchar(5), @scheduledate datetime BEGIN SELECT scheduleroute, scheduleorigin + ' TO ' + scheduledestination as journey, convert(varchar,scheduletime,108) as scheduletime FROM tbl_busschedule WHERE scheduleroute = @route AND scheduledate = @scheduledate AND schedulelocationtype = 'O' ORDER BY scheduletime END 70
5.1 Documentation Generation Software 5.1.1 Sandcastle / Sandcastle Help File Builder Sandcastle is a Microsoft tool used to generate MSDN-style documentation from.net applications using pre-defined XML comment rules. Sandcastle is a command line tool but used along with the Sandcastle Help File Builder provides a GUI based application for generating documentation in HTML format. 71
REST Architecture Style. (2000). Retrieved from http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm Consuming WCF Services with Android. (2010). Retrieved from http://fszlin.dymetis.com/post/2010/05/10/comsuming-wcf-services-with-android.aspx Facebook API Home. (2011). Retrieved from http://developers.facebook.com/docs/samples/ Metro Trip Planner - Home. (2011). Retrieved from http://developer.metro.net/introduction/tp-informationfeed/overview/ Metro Trip Planner on www.programmableweb.com. (2011). Retrieved from http://www.programmableweb.com/api/metro-trip-planner Transport For London - Home. (2011). Retrieved from http://www.tfl.gov.uk/businessandpartners/syndication/default.aspx Transport For London on www.programmableweb.com. (2011). Retrieved from http://www.programmableweb.com/api/transport-for-london: http://www.programmableweb.com/api/transport-for-london www.programmableweb.com. (2011). Retrieved 2011, from API Directory: www.programmableweb.com (2007). The Elements of UML 2.0. In S. W. Ambler. (2005). Systems Analysis and Design with UML Version 2.0. In A. Dennis, B. Haley Wixom, & D. Tegarden. Wiley. Designing and Building RESTful Web Services. (n.d.). Retrieved from http://msdn.microsoft.com/enus/library/dd203052.aspx Dewson, R. (2008). Beginning SQL Server for Developers. Apress. Flanders, J. (2009). RESTful.NET. O'Reilly. (n.d.). Foundations of Software Testing. In Graham Dorothy, E. Van Veenendal, I. Evans, & R. Black. Rattz, J. C. (2010). Pro LINQ. Apress. 72