public static DarwinDepartureBoard GetGetEntireBoard(string crs, int offset, int window) { try { LDBServiceSoapClient client = new LDBServiceSoapClient(); StationBoardWithDetails board = null; using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { MessageHeader authHeader = MessageHeader.CreateHeader("AccessToken", @"http://thalesgroup.com/RTTI/2013-11-28/Token/types", DarwinToken.TheAccessToken); OperationContext.Current.OutgoingMessageHeaders.Add(authHeader); //Note that this is called on a background thread - I don't need to make it async. Doing so causes a range of exciting race hazards further on GetDepBoardWithDetailsResponse response = client.GetDepBoardWithDetailsAsync(0, crs, string.Empty, FilterType.from, offset, window).Result; board = (StationBoardWithDetails)response.GetStationBoardResult; } return(DarwinDepartureBoardFactory.CreateDepartureBoard(board)); } catch (AggregateException ae) { crashDump(ae); return(null); } catch (System.Runtime.InteropServices.SEHException seh) { crashDump(seh); return(null); } }
// GET /service/ID?accessToken=[your token] public async Task <ServiceDetails> Get([FromUri] ServiceRequest request) { Guid sid; if (Guid.TryParse(request.ServiceId, out sid)) { request.ServiceId = Convert.ToBase64String(sid.ToByteArray()); } var client = new LDBServiceSoapClient(); // Avoiding Problems with the Using Statement in WCF clients // https://msdn.microsoft.com/en-us/library/aa355056.aspx try { var token = MakeAccessToken(request.AccessToken); var service = await client.GetServiceDetailsAsync(token, request.ServiceId); return(service.GetServiceDetailsResult); } catch (CommunicationException) { client.Abort(); } catch (TimeoutException) { client.Abort(); } catch (Exception) { client.Abort(); throw; } finally { client.Close(); } return(new ServiceDetails()); }
public RailWebservice(string accessToken) { _accessToken = new AccessToken() { TokenValue = accessToken }; _service = new LDBServiceSoapClient(); }
public async Task <DeparturesBoardModel> GetFastest(FastestDepartureQuery query) { var endpoint = default(LDBServiceSoapClient.EndpointConfiguration); var svc = new LDBServiceSoapClient(endpoint); var board = await svc.GetFastestDeparturesWithDetailsAsync(Mapper.Map <GetFastestDeparturesWithDetailsRequest>(query)); return(Mapper.Map <DeparturesBoardModel>(board)); }
// GET /arrivals/CRS?accessToken=[your token] public async Task <StationBoard> Get(string id, Guid accessToken) { var client = new LDBServiceSoapClient(); var token = MakeAccessToken(accessToken); var board = await client.GetArrivalBoardAsync(token, 42, id.ToUpperInvariant(), null, FilterType.to, 0, 0); return(board.GetStationBoardResult); }
public async Task<IHttpActionResult> ServiceDetails(ServiceDetailsHolder service) { using (var darwin = new LDBServiceSoapClient()) { var result = await darwin.GetServiceDetailsAsync(DarwinToken, service.ServiceId); if (result == null) return NotFound(); return Ok(result.GetServiceDetailsResult); } }
public async Task <StationBoardModel> GetBoard(StationBoardQuery query) { var endpoint = default(LDBServiceSoapClient.EndpointConfiguration); var svc = new LDBServiceSoapClient(endpoint); var board = await svc.GetArrDepBoardWithDetailsAsync(Mapper.Map <GetArrDepBoardWithDetailsRequest>(query)); // TODO: TEST PROPERLY!! (with unit tests) // var board = ReadFile<GetArrDepBoardWithDetailsResponse>.GetFromJson("~/../../../Data/DepArrBoard_HHEECR_Arr_NotStopping.json"); return(Mapper.Map <StationBoardModel>(board)); }
public static DarwinDepartureBoard GetGetEntireBoard(string crs, int offset, int window) { try { Darwin.LDBServiceSoapClient client = new LDBServiceSoapClient(); StationBoardWithDetails board = client.GetDepBoardWithDetails(DarwinToken.TheAccessToken, 0, crs, string.Empty, FilterType.from, offset, window); return(DarwinDepartureBoardFactory.CreateDepartureBoard(board)); } catch (Exception ex) { Logging.LogError(ex, "Whilst getting Departure Board", 1); return(null); } }
public static DarwinDepartureBoard GetGetEntireBoard(string crs, int offset, int window) { try { Darwin.LDBServiceSoapClient client = new LDBServiceSoapClient(); StationBoardWithDetails board = client.GetDepBoardWithDetails(DarwinToken.TheAccessToken, 0, crs, string.Empty, FilterType.from, offset, window); return DarwinDepartureBoardFactory.CreateDepartureBoard(board); } catch (Exception ex) { Logging.LogError(ex, "Whilst getting Departure Board", 1); return null; } }
public async Task<IHttpActionResult> StationServices(string crsCode, string toCrsCode) { using (var darwin = new LDBServiceSoapClient()) { var toResult = darwin.GetArrivalDepartureBoardAsync(DarwinToken, 20, crsCode, toCrsCode, FilterType.to, -30, 60); var fromResult = darwin.GetArrivalDepartureBoardAsync(DarwinToken, 20, crsCode, toCrsCode, FilterType.from, -30, 60); await Task.WhenAll(new[] { toResult, fromResult }); return Ok(new[] { toResult.Result.GetStationBoardResult, fromResult.Result.GetStationBoardResult }); } }
// GET /service/ID?accessToken=[your token] public async Task <ServiceDetails> Get(string id, Guid accessToken) { Guid sid; if (Guid.TryParse(id, out sid)) { id = Convert.ToBase64String(sid.ToByteArray()); } var client = new LDBServiceSoapClient(); var token = MakeAccessToken(accessToken); var service = await client.GetServiceDetailsAsync(token, id); return(service.GetServiceDetailsResult); }
// GET /{board}/CRS?accessToken=[your token] public async Task <StationBoard> Get([FromUri] StationBoardRequest request) { // Process CRS codes request.Crs = MakeCrsCode(request.Crs); request.FilterCrs = MakeCrsCode(request.FilterCrs); var client = new LDBServiceSoapClient(); // Avoiding Problems with the Using Statement in WCF clients // https://msdn.microsoft.com/en-us/library/aa355056.aspx try { var token = MakeAccessToken(request.AccessToken); if (Board.Departures == request.Board) { var departures = await client.GetDepartureBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0); return(departures.GetStationBoardResult); } if (Board.Arrivals == request.Board) { var arrivals = await client.GetArrivalBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0); return(arrivals.GetStationBoardResult); } // Default all (departures and arrivals board) var board = await client.GetArrivalDepartureBoardAsync(token, request.NumRows, request.Crs, request.FilterCrs, request.FilterType, 0, 0); return(board.GetStationBoardResult); } catch (CommunicationException) { client.Abort(); } catch (TimeoutException) { client.Abort(); } catch (Exception) { client.Abort(); throw; } finally { client.Close(); } return(new StationBoard()); }
public Connection(Binding binding, EndpointAddress remoteAddress, string token) { accessToken = new AccessToken(); accessToken.TokenValue = token; service = new LDBServiceSoapClient(binding, remoteAddress); }
public LdbClient(LDBServiceSoapClient client) { this.client = client; }
// GET /delays/{crs}/{filtertype}/{filtercrs}/{numrows}/{stds}?accessToken=[your token] public async Task <DelaysResponse> Get([FromUri] StationBoardRequest request) { // Process CRS codes request.Crs = MakeCrsCode(request.Crs); request.FilterCrs = MakeCrsCode(request.FilterCrs); // Parse the list of comma separated STDs if provided (e.g. /btn/to/lon/50/0729,0744,0748) var stds = new List <string>(); if (!string.IsNullOrWhiteSpace(request.Std)) { var potentialStds = request.Std.Split(','); var ukNow = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time")); var dontRequest = 0; foreach (var potentialStd in potentialStds) { DateTime requestStd; // Parse the STD in 24-hour format (with no colon) if (!DateTime.TryParseExact(potentialStd, "HHmm", CultureInfo.InvariantCulture, DateTimeStyles.None, out requestStd)) { continue; } stds.Add(potentialStd); var diff = requestStd.Subtract(ukNow); if (diff.TotalHours > 2 || diff.TotalHours < -1) { dontRequest++; } } // Don't make a request if all trains are more than 2 hours in the future or more than 1 hour in the past if (stds.Count > 0 && stds.Count == dontRequest) { return(new DelaysResponse()); } } var londonTerminals = new List <string> { "BFR", "LBG", "CST", "CHX", "EUS", "FST", "KGX", "LST", "MYB", "PAD", "STP", "SPX", "VIC", "WAT", "WAE", }; var client = new LDBServiceSoapClient(); // Avoiding Problems with the Using Statement in WCF clients // https://msdn.microsoft.com/en-us/library/aa355056.aspx try { var totalDelayMinutes = 0; var delayedTrains = new List <ServiceItem>(); var token = MakeAccessToken(request.AccessToken); var filterCrs = request.FilterCrs; if (request.FilterCrs.Equals("LON", StringComparison.InvariantCultureIgnoreCase) || request.FilterCrs.Equals("London", StringComparison.InvariantCultureIgnoreCase)) { filterCrs = null; } var board = await client.GetDepartureBoardAsync(token, request.NumRows, request.Crs, filterCrs, request.FilterType, 0, 0); var response = board.GetStationBoardResult; var filterLocationName = response.filterLocationName; var trainServices = response.trainServices ?? new ServiceItem[0]; var railReplacement = null != response.busServices && !trainServices.Any() && response.busServices.Any(); var messagesPresent = null != response.nrccMessages && response.nrccMessages.Any(); if (null == filterCrs) { // This only finds trains terminating at London terminals. BFR/STP etc. won't be picked up if called at en-route. // Could query for every terminal or get service for every train and check calling points. Very chatty either way. switch (request.FilterType) { case FilterType.to: trainServices = trainServices.Where(ts => ts.destination.Any(d => londonTerminals.Contains(d.crs.ToUpperInvariant()))).ToArray(); break; case FilterType.from: trainServices = trainServices.Where(ts => ts.origin.Any(d => londonTerminals.Contains(d.crs.ToUpperInvariant()))).ToArray(); break; default: throw new ArgumentOutOfRangeException(); } filterCrs = "LON"; filterLocationName = "London"; } // If STDs are provided then select only the train(s) matching them if (stds.Count > 0) { trainServices = trainServices.Where(ts => stds.Contains(ts.std.Replace(":", ""))).ToArray(); } // Parse the response from the web service. foreach (var si in trainServices.Where(si => !si.etd.Equals("On time", StringComparison.InvariantCultureIgnoreCase))) { if (si.etd.Equals("Delayed", StringComparison.InvariantCultureIgnoreCase) || si.etd.Equals("Cancelled", StringComparison.InvariantCultureIgnoreCase)) { delayedTrains.Add(si); } else { DateTime etd; // Could be "Starts Here", "No Report" or contain a * (report overdue) if (DateTime.TryParse(si.etd.Replace("*", ""), out etd)) { DateTime std; if (DateTime.TryParse(si.std, out std)) { var late = etd.Subtract(std); totalDelayMinutes += (int)late.TotalMinutes; if (late.TotalMinutes > HuxleyApi.Settings.DelayMinutesThreshold) { delayedTrains.Add(si); } } } } } return(new DelaysResponse { GeneratedAt = response.generatedAt, Crs = response.crs, LocationName = response.locationName, Filtercrs = filterCrs, FilterLocationName = filterLocationName, Delays = delayedTrains.Count > 0 || railReplacement || messagesPresent, TotalTrainsDelayed = delayedTrains.Count, TotalDelayMinutes = totalDelayMinutes, TotalTrains = trainServices.Length, DelayedTrains = delayedTrains, }); } catch (CommunicationException) { client.Abort(); } catch (TimeoutException) { client.Abort(); } catch (Exception) { client.Abort(); throw; } finally { client.Close(); } return(new DelaysResponse()); }
public LdbClient(LDBServiceSoapClient client, ldbStaffServiceReference.LDBSVServiceSoapClient staffClient) { this.client = client; this.staffClient = staffClient; }
//process of getting the Train rows. public List <DepartureBoardRowDTO> GetTrainDepartureBoards(String stationCode) { List <DepartureBoardRowDTO> rows = new List <DepartureBoardRowDTO>(); try { //connectiong to Train api. var nrServiceClient = new LDBServiceSoapClient(); StationBoardWithDetails2 board = nrServiceClient.GetDepBoardWithDetails( new AccessToken { TokenValue = "94e96b3b-ee5d-43cb-ac3b-d49b5520579c" }, 100, stationCode, String.Empty, FilterType.to, 0, 120); //process of adding to the list rows. foreach (var s in board.trainServices) { //remove what is gonna be set as Destination(since it is not to be included in via later) var k = s.subsequentCallingPoints.FirstOrDefault().callingPoint.ToList(); k.Reverse(); k.Remove(k.First()); k.Reverse(); //Test of doing it through editing strings, was replaced with Reversing and removing. /*string.join(string,array) * for(int i = 0; i<s.subsequentCallingPoints.FirstOrDefault().callingPoint.Length-2; i++) * { * points = points + s.subsequentCallingPoints.FirstOrDefault().callingPoint[i].locationName; * points = points + ", "; * } * points = points + s.subsequentCallingPoints.FirstOrDefault().callingPoint[s.subsequentCallingPoints.FirstOrDefault().callingPoint.Length - 2].locationName; */ //figure out the time to give it. var now = board.generatedAt; var sched = s.std; TimeSpan ts = TimeSpan.Parse(sched); var expect = now.Date + ts; //create flatened object and add to list of rows. DepartureBoardRowDTO dep = new DepartureBoardRowDTO { StationName = board.locationName, Destination = s.subsequentCallingPoints.LastOrDefault().callingPoint.LastOrDefault().locationName, Via = String.Join(", ", k.Select(name => name.locationName)), ScheduledTime = expect.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss"), Expected = s.etd, Platform = s.platform }; rows.Add(dep); } } catch { rows.Add(Error("TRAIN")); } return(rows); }