public static async Task <TransitStop[]> GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { if (area.Span.Latitude > 1 || area.Span.Longitude > 1) { return(null); } List <TransitStop> result = new List <TransitStop>(); var responseString = await SendRequest("stops-for-location", new Dictionary <string, string>() { ["lat"] = area.Center.Latitude.ToString(), ["lon"] = area.Center.Longitude.ToString(), ["latSpan"] = area.Span.Latitude.ToString(), ["lonSpan"] = area.Span.Longitude.ToString() }, false, cancellationToken); if (cancellationToken.IsCancellationRequested) { return(null); } StringReader reader = new StringReader(responseString); XDocument xDoc = XDocument.Load(reader); //XElement el = (XElement)xDoc.Nodes().First(d => d.NodeType == XmlNodeType.Element && ((XElement)d).Name.LocalName == "response"); XElement el = xDoc.Element("response").Element("data"); XElement elList = el.Element("list"); foreach (XElement el1 in elList.Elements("stop")) { result.Add(ParseTransitStop(el1)); } return(result.ToArray()); }
public override Task <RetrievedData <IEnumerable <TransitStop> > > GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { var result = MemoryCache.QueryStops(stop => area.ContainsLatLon(stop.Position)); return(Task.FromResult(new RetrievedData <IEnumerable <TransitStop> >(result))); }
public MapView(LatLonRect area) { Area = area; }
public override async Task <RetrievedData <IEnumerable <TransitStop> > > GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { try { if (area.Span.Latitude > 1 || area.Span.Longitude > 1) { return(null); } var responseString = await SendRequest("stops-for-location", new Dictionary <string, string>() { ["lat"] = area.Center.Latitude.ToString(), ["lon"] = area.Center.Longitude.ToString(), ["latSpan"] = area.Span.Latitude.ToString(), ["lonSpan"] = area.Span.Longitude.ToString() }, false, cancellationToken); if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(); } StringReader reader = new StringReader(responseString); XDocument xDoc = XDocument.Load(reader); //XElement el = (XElement)xDoc.Nodes().First(d => d.NodeType == XmlNodeType.Element && ((XElement)d).Name.LocalName == "response"); XElement el = xDoc.Element("response").Element("data"); XElement elList = el.Element("list"); return(new RetrievedData <IEnumerable <TransitStop> >(ParseList(elList, "stop", ParseTransitStop))); } catch (OperationCanceledException) { return(new RetrievedData <IEnumerable <TransitStop> >()); } catch (Exception ex) { return(new RetrievedData <IEnumerable <TransitStop> >(ex)); } }
public override Task <RetrievedData <IEnumerable <TransitStop> > > GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { return(Task.FromResult(new RetrievedData <IEnumerable <TransitStop> >(Stops.Where(stop => area.ContainsLatLon(stop.Position))))); }
public abstract Task <RetrievedData <IEnumerable <TransitStop> > > GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken);
public static RetrievedData <IEnumerable <TransitStop> > GetTransitStopsForArea(LatLonRect area, DataSourcePreference preference) => RunSync(() => GetTransitStopsForAreaAsync(area, preference, CancellationToken.None));
public static async Task <RetrievedData <IEnumerable <TransitStop> > > GetTransitStopsForAreaAsync(LatLonRect area, DataSourcePreference preference, CancellationToken cancellationToken) { IEnumerable <TransitStop> resultStops = null; List <string> resultErrors = new List <string>(); List <Exception> resultExceptions = new List <Exception>(); foreach (var source in Sources) { if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(); } if (!source.IsQualified(preference)) { continue; } if (source.CanGetTransitStopsForArea) { var sResult = await source.GetTransitStopsForArea(area, cancellationToken); if (sResult.HasData) { if (resultStops == null) { resultStops = sResult.Data; } else { resultStops = resultStops.Union(sResult.Data); } } if (sResult.ErrorMessage != null) { resultErrors.Add(sResult.ErrorMessage); } if (sResult.CaughtException != null) { resultExceptions.Add(sResult.CaughtException); } } } if (resultStops == null) { resultStops = new TransitStop[] { } } ; return(new RetrievedData <IEnumerable <TransitStop> >(resultStops, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions))); }