public static Agency FromNextBusAgency( NextBus.NET.Models.Agency nextbusAgency ) => new Agency { Tag = NonEmptyValue(nextbusAgency.Tag), Title = NonEmptyValue(nextbusAgency.Title), ShortTitle = NonEmptyValue(nextbusAgency.ShortTitle), Region = NonEmptyValue(nextbusAgency.RegionTitle), };
private async Task SeedAgencyDataAsync(NextbusAgency nxtbAgency) { var nxtbRoutes = (await _nextBusClient.GetRoutesForAgency(nxtbAgency.Tag).ConfigureAwait(false)).ToArray(); Agency agency = (Agency)nxtbAgency; { // Populate first agency coords var routeConfig = await _nextBusClient.GetRouteConfig(nxtbAgency.Tag, nxtbRoutes[0].Tag) .ConfigureAwait(false); agency.MinLatitude = (double)routeConfig.LatMin; agency.MaxLatitude = (double)routeConfig.LatMax; agency.MinLongitude = (double)routeConfig.LonMin; agency.MaxLongitude = (double)routeConfig.LonMax; } List <AgencyRoute> routes = new List <AgencyRoute>(90); foreach (var nxtbRoute in nxtbRoutes) { // for testing //if ( // (agency.Tag == "ttc" && !new[] { "57", "85", "190" }.Contains(nxtbRoute.Tag)) // || (agency.Tag == "jtafla" && !new[] { "53" }.Contains(nxtbRoute.Tag)) // ) //{ // continue; //} var routeConfig = await _nextBusClient.GetRouteConfig(nxtbAgency.Tag, nxtbRoute.Tag) .ConfigureAwait(false); AgencyRoute route = (AgencyRoute)routeConfig; UpdateAgencyMinMaxCoordinates(ref agency, route.MaxLatitude, route.MinLatitude, route.MaxLongitude, route.MinLongitude); BusStop[] busStops = GetAllBusStopsPersistNew(routeConfig.Stops); List <RouteDirection> directions = new List <RouteDirection>(routeConfig.Directions.Length); foreach (NextbusDirection nextbusDir in routeConfig.Directions) { RouteDirection dir = (RouteDirection)nextbusDir; dir.RouteDirectionBusStops.Capacity = nextbusDir.StopTags.Length; foreach (string stopTag in nextbusDir.StopTags) { // try // { BusStop stop = busStops.Single(s => s.Tag == stopTag); dir.RouteDirectionBusStops.Add(new RouteDirectionBusStop(dir, stop)); // } // catch (Exception e) // { // Console.WriteLine(e); // throw; // } } directions.Add(dir); } route.Directions = directions; routes.Add(route); } agency.Routes = routes; if (agency.Tag.Equals(TestAgencyTag, StringComparison.OrdinalIgnoreCase)) { agency.Country = TestAgencyTag; } _dbContext.Agencies.Add(agency); await _dbContext.SaveChangesAsync().ConfigureAwait(false); }