public IActionResult Edit(int id, RouteDto routeDto) { log.Info(nameof(RoutesController.Edit)); if (id != routeDto.Id) { log.Warn(nameof(RoutesController.Edit) + " id isn't equal to routeDto.Id"); return(NotFound()); } try { if (ModelState.IsValid) { routeService.Update(routeDto); return(RedirectToAction(nameof(Index))); } var stationNames = stationService.GetAll(); ViewData["StationId"] = new SelectList(stationNames, "Id", "Name", routeDto.Id); return(View(routeDto)); } catch (Exception e) { log.Error(e); return(BadRequest()); } }
public IActionResult Create(RouteDto routeDto) { log.Info(nameof(RoutesController.Create)); try { if (ModelState.IsValid) { routeService.Create(routeDto); return(RedirectToAction(nameof(Index))); } var stationNames = stationService.GetAll(); ViewData["StationId"] = new SelectList(stationNames, "Id", "Name", routeDto.Id); return(View(routeDto)); } catch (Exception e) { log.Error(e); return(BadRequest()); } }
public void AddCurrentRoute_CorrectData_RouteCreated() { CourierDto courier = new CourierDto() { FirstName = "Courier", LastName = "With route", PhoneNumber = "test" }; Guid id = courierService.AddCourierAsync(courier).Result; RouteDto route = new RouteDto() { Created = DateTime.Now, Points = new List <PointDto> { new PointDto { Latitude = 49.8333981, Longitude = 24.0125249 }, new PointDto { Latitude = 49.8306805, Longitude = 24.034673 }, new PointDto { Latitude = 49.8388715, Longitude = 24.0311097 } } }; Guid routeId = routeService.AddRouteAsync(id, route).Result; Assert.IsTrue(routeId != Guid.Empty); }
public void Create(RouteDto routeDto) { var routeService = mapper.Map <RouteDto, Route>(routeDto); unitOfWork.Routes.Create(routeService); unitOfWork.Save(); }
private List <RailwayStation> GetStations(RouteDto entity) { _logger.Debug($"Getting list of all stations..."); int[] ids = entity.RailwayStations.Select(s => s.Id).ToArray(); return(_unitOfWork.RailwayStations.GetAll(station => ids.Contains(station.Id)).ToList()); }
public async Task <IEnumerable <RouteDto> > GetRoutesFromCommandsAsync(string rawRobotsCommands) { var routeDtos = new List <RouteDto>(); var robotCommandsWithoutComments = await GetRobotCommandsWithoutCommentsAsync(rawRobotsCommands); var startingPositionsAndRouteSteps = await GetStartingPositionsAndRouteStepsAsync(robotCommandsWithoutComments); foreach (var startingPositionAndRouteStep in startingPositionsAndRouteSteps) { var startingPosition = await GetStartingPositionAsync(startingPositionAndRouteStep); var routeSteps = await GetRouteStepsAsync(startingPositionAndRouteStep); var routeDto = new RouteDto { StartingPosition = startingPosition, RouteSteps = routeSteps }; routeDtos.Add(routeDto); } return(routeDtos); }
public IActionResult UpdateRoute([FromBody] RouteDto routeDto) { try { var route = _mapper.Map <Route>(routeDto); if (this.HttpContext.GetUserId() != route.UserId) { return(Forbid()); } var dbInstance = _rep.GetRoute(route.RouteId); if (dbInstance != null) { dbInstance.UpdateRoute(route); _uof.Complete(); } return(Ok()); } catch { return(BadRequest()); } }
public IEnumerable <RideDto> GetRidesByDriver(string email) { IEnumerable <Ride> rides = _rideRepository.GetRidesByDriver(email); List <RideDto> dtoRide = new List <RideDto>(); int count = 0; foreach (var ride in rides) { RouteDto route = _routeLogic.GetRouteById(ride.RouteId); dtoRide.Add(_mapper.Map <Ride, RideDto>(ride)); AddressDto fromAddress = _addressLogic.GetAddressById(route.FromId); dtoRide[count].FromCountry = fromAddress.Country; dtoRide[count].FromCity = fromAddress.City; dtoRide[count].FromStreet = fromAddress.Street; dtoRide[count].FromNumber = fromAddress.Number; AddressDto toAddress = _addressLogic.GetAddressById(route.ToId); dtoRide[count].ToCountry = toAddress.Country; dtoRide[count].ToCity = toAddress.City; dtoRide[count].ToStreet = toAddress.Street; dtoRide[count].ToNumber = toAddress.Number; count++; } return(dtoRide); }
public async Task ChangeCourierCurrentRouteAsync(Guid courierId, RouteDto newCurrentRouteDto) { using (var db = new CourierHelperDb(_connectionString)) { Courier courier = db.CouriersRepo.Get(courierId); if (courier == null) { throw new ArgumentException(); //todo: exception } Route currentRoute = courier.Routes.FirstOrDefault(r => r.IsCurrent); foreach (var point in currentRoute.Points.ToList()) { db.ActivePointsRepo.Delete(point); } foreach (var point in newCurrentRouteDto.Points) { currentRoute.Points.Add(new ActivePoint() { Coordinates = new Point(point.Longitude, point.Latitude) }); } db.RoutesRepo.Update(currentRoute); await db.SaveAsync(); } }
public IActionResult UpdateRoute(int id, RouteDto routeDto) { log.Info(nameof(RoutesController.UpdateRoute)); try { if (id != routeDto.Id | routeDto == null) { return(BadRequest()); } if (!routeService.Exists(id)) { return(NotFound()); } routeService.Update(routeDto); return(Ok(routeDto)); } catch (Exception e) { log.Error(e); return(BadRequest()); } }
private async Task <RouteCandidate> FindBestCandidateAsync(IEnumerable <CourierDto> couriers, PointDto orderPoint) { List <PointDto> pointsDto = new List <PointDto>(); SortedList <double, RouteCandidate> candidates = new SortedList <double, RouteCandidate>(); foreach (var courier in couriers) { pointsDto.Add(courier.Location); pointsDto.Add(orderPoint); List <OrderDto> courierOrders = _orderService.GetCourierOrders(courier.Id); foreach (var courierOrder in courierOrders) { var location = _pointService.GetOrderLocation(courierOrder.Id); pointsDto.Add(location); } var optimizedPointsOrder = await _mapBoxService.OptimizeRouteAsync(pointsDto.ToArray()); var optimizedRoute = await _mapBoxService.BuildRouteAsync(optimizedPointsOrder); RouteDto currentRoute = _routeService.GetCourierCurrentRoute(courier.Id); candidates.Add(optimizedRoute.Distance - currentRoute.Distance, optimizedRoute); } return(candidates.FirstOrDefault().Value); }
public async Task CreateAsync_ValidData_Successful() { // Arrange. Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, TripRoleEntitiesToSeed); Seed(TripFlipDbContext, TripSubscriberRoleEntitiesToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var createRouteDto = GetCreateRouteDto(); var routeService = new RouteService(TripFlipDbContext, Mapper, CurrentUserService); var routeDtoComparer = new RouteDtoComparer(); var expectedRouteDto = new RouteDto() { Id = 1, Title = createRouteDto.Title, TripId = createRouteDto.TripId }; // Act. var resultItemDto = await routeService.CreateAsync(createRouteDto); // Assert. Assert.AreEqual(0, routeDtoComparer.Compare(expectedRouteDto, resultItemDto)); }
public void TrueWhenRouteHasSameName() { var dto = new RouteDto {Name = "intraveneus", Abbreviation = "iv"}; var route = CreateRoute(dto); var route2 = CreateRoute(dto); Assert.IsTrue(_comparer.Equals(route, route2)); }
public RouteDto AddRoute(RouteDto route) { var newRoute = route.MapTo <Route>(); _writeRepository.Add(newRoute); _unitOfWork.Commit(); return(newRoute.MapTo <RouteDto>()); }
public async Task <RouteDto> Update(RouteDto input) { var entity = _routeRepository.Get(input.Id); ObjectMapper.Map <RouteDto, Route>(input, entity); await _routeRepository.UpdateAsync(entity); return(ObjectMapper.Map <RouteDto>(entity)); }
public async Task FetchFullDownloadableDataIntoDatabase( string routeId, int idForRestApi, CancellationToken token, IProgressListener listener) { routeDto = (await routesApiAccess.GetRoutes(new List <int> { idForRestApi })).Items.First(); if (token.IsCancellationRequested) { return; } route = DbManager.DataAccess.Routes().GetRoute(routeId); pagesAndMediaForMissingExhibits = new List <ExhibitPagesAndMediaContainer>(); var allMissingExhibits = DbManager.DataAccess.Exhibits().GetExhibits().ToList().FindAll(x => !x.DetailsDataLoaded); // Exhibits not fully loaded yet missingExhibitsForRoute = allMissingExhibits.ToList().FindAll(x => routeDto.Exhibits.Contains(x.IdForRestApi)); // Select those part of the route double totalSteps = FetchNeededMediaForFullRoute(); foreach (var exhibit in missingExhibitsForRoute) // Fetch media for missing exhibits and save them for later download { var pagesAndRequiredMediaForExhibit = await fullExhibitDataFetcher.FetchPagesAndMediaForExhibitFromRouteFetcher(exhibit.IdForRestApi); if (token.IsCancellationRequested) { return; } pagesAndMediaForMissingExhibits.Add(pagesAndRequiredMediaForExhibit); totalSteps += pagesAndRequiredMediaForExhibit.RequiredMedia.Count; } listener.SetMaxProgress(totalSteps); await AddFullExhibitsToRoute(route, token, listener); // Download all missing exhibits if (token.IsCancellationRequested) { return; } await FetchMediaData(token, listener); var mediaToFilePath = await mediaDataFetcher.WriteMediaToDiskAsync(); DbManager.InTransaction(transaction => { var dataAccess = transaction.DataAccess; ProcessRoute(token, dataAccess, mediaToFilePath); // Download audio if (token.IsCancellationRequested) { transaction.Rollback(); } }); }
public async Task <IEnumerable <RouteDto> > GetRoutesAsync(RouteDto routeDto, string email) { List <RouteDto> routes = _routeLogic.GetRoutes(routeDto, email); foreach (RouteDto route in routes) { await AddDriversNamesToRouteRidesAsync(route.Rides); } return(routes); }
public void TrueWhenRouteHasSameAbbreviation() { var dto = new RouteDto { Name = "intraveneus", Abbreviation = "iv" }; var route = CreateRoute(dto); var route2 = CreateRoute(dto); Assert.IsTrue(_comparer.Equals(route, route2)); }
public IEnumerable <RouteDto> GetRoutes(RouteDto routeDto, string email) { List <RouteDto> routes = _routeLogic.GetRoutes(routeDto, email); foreach (RouteDto route in routes) { AddDriversNamesToRouteRides(route.Rides); } return(routes); }
public static ProductDto GetParacetamolDto() { var subst = new ProductSubstanceDto { Id = Guid.NewGuid().ToString(), Name = "paracetamol", Quantity = 500, SortOrder = 1, Substance = "paracetamol", UnitAbbreviation = "mg", UnitDivisor = 1000, UnitGroupAllowConversion = true, UnitGroupName = "massa", UnitIsReference = false, UnitMultiplier = 1 / 1000, UnitName = "milligram" }; var route = new RouteDto { Id = Guid.NewGuid().ToString(), Name = "oraal", Abbreviation = "or" }; var dto = new ProductDto { BrandName = "", GenericName = "paracetamol", DisplayName = "paracetamol 500 mg tablet", Id = Guid.NewGuid().ToString(), Name = DisplayName, PackageAbbreviation = "tabl", PackageName = "tablet", ProductCode = "2", Quantity = 1M, Routes = new List <RouteDto> { route }, ShapeName = "tablet", Substances = new List <ProductSubstanceDto> { subst }, UnitAbbreviation = "stuk", UnitDivisor = 1, UnitGroupAllowConversion = false, UnitGroupName = "verpakking", UnitIsReference = false, UnitMultiplier = 1, UnitName = "stuk" }; return(dto); }
public static Route Create(RouteDto dto) { var route = new Route { Name = dto.Name, Abbreviation = dto.Abbreviation }; Validate(route); return(route); }
private void AssertEqual(Route route, RouteDto dto) { Assert.Equal(route.Id, dto.Id); Assert.Equal(route.Mark, dto.Mark); Assert.Equal(route.Name, dto.Name); Assert.All(route.RailwayStations, station => { var stationDto = dto.RailwayStations.Single(s => s.Id == station.Id); AssertEqual(station, stationDto); }); }
public static Route toEntity(this RouteDto obj) { return(new Route() { CreatedAt = obj.CreatedAt, Destination = obj.Destination, Origin = obj.Origin, User = obj.User.toEntity(), Id = obj.Id }); }
private void OverwriteExisting(RouteDto entity, Route dbRoute) { _logger.Debug($"Overwriting existing (logically deleted) route {dbRoute.Id}..."); _mapper.Map(entity, dbRoute); dbRoute.RailwayStations = GetStations(entity); dbRoute.DeletionDate = null; _unitOfWork.SaveChanges(); _logger.Info($"Overwrote route {dbRoute.Id}!"); }
public RouteDto UpdateRoute(string id, RouteDto route) { var item = _readRepository.Get(x => x.Id.Equals(Guid.Parse(id))).FirstOrDefault(); if (item != null) { _writeRepository.Update(route.MapTo <Route>()); _unitOfWork.Commit(); return(item.MapTo <RouteDto>()); } throw new ArgumentException("The passed route doesn't exist."); }
private static void AssertCreateFails(RouteDto dto) { try { Route.Create(dto); Assert.Fail(); } catch (Exception e) { Assert.IsNotInstanceOfType(e, typeof (AssertFailedException)); } }
public async Task <IActionResult> GetRoutesAsync([FromBody] RouteDto routeDto) { if (routeDto.FromAddress == null && routeDto.ToAddress == null) { return(BadRequest()); } var userDto = await _userRepository.GetLoggedInUser(User); IEnumerable <RouteDto> routes = _rideLogic.GetRoutes(routeDto, userDto.Email); return(Ok(routes)); }
private static void AssertCreateFails(RouteDto dto) { try { Route.Create(dto); Assert.Fail(); } catch (Exception e) { Assert.IsNotInstanceOfType(e, typeof(AssertFailedException)); } }
public async Task <PositionDto> CalculateRoutesEndPositionAsync(RouteDto routeDto) { var routeSteps = await ParseRouteAsync(routeDto.RouteSteps); if (routeSteps == null) { return(routeDto.StartingPosition); } var endPoint = await CalculateRouteEndPointAsync(routeDto.StartingPosition, routeSteps); return(endPoint); }
public async Task <IHttpActionResult> SyncRoutes(Guid courierId) { RouteDto route = await RouteService.SyncRoute(courierId); if (route != null) { return(Ok(route)); } else { return(StatusCode(HttpStatusCode.NotModified)); } }
public void AddRoute(RouteDto route) { Route entityRoute = new Route { FromId = route.FromId, ToId = route.ToId, Geometry = route.Geometry, FromAddress = _mapper.Map <AddressDto, Address>(route.FromAddress), ToAddress = _mapper.Map <AddressDto, Address>(route.ToAddress) }; _routeRepository.AddRoute(entityRoute); }
public RouteDto GetRouteById(int id) { Route route = _routeRepository.GetRouteById(id); if (route == null) { return(null); } RouteDto routeDto = _mapper.Map <Route, RouteDto>(route); return(routeDto); }
public static ProductDto GetParacetamolDto() { var subst = new ProductSubstanceDto { Id = Guid.NewGuid().ToString(), Name = "paracetamol", Quantity = 500, SortOrder = 1, Substance = "paracetamol", UnitAbbreviation = "mg", UnitDivisor = 1000, UnitGroupAllowConversion = true, UnitGroupName = "massa", UnitIsReference = false, UnitMultiplier = 1/1000, UnitName = "milligram" }; var route = new RouteDto { Id = Guid.NewGuid().ToString(), Name = "oraal", Abbreviation = "or" }; var dto = new ProductDto { BrandName = "", GenericName = "paracetamol", DisplayName = "paracetamol 500 mg tablet", Id = Guid.NewGuid().ToString(), Name = DisplayName, PackageAbbreviation = "tabl", PackageName = "tablet", ProductCode = "2", Quantity = 1M, Routes = new List<RouteDto> { route }, ShapeName = "tablet", Substances = new List<ProductSubstanceDto> {subst}, UnitAbbreviation = "stuk", UnitDivisor = 1, UnitGroupAllowConversion = false, UnitGroupName = "verpakking", UnitIsReference = false, UnitMultiplier = 1, UnitName = "stuk" }; return dto; }
/// <summary> /// Fullfills pathfinding requests by returning a Route object. /// </summary> /// <param name="startX"></param> /// <param name="endX"></param> /// <param name="startY"></param> /// <param name="endY"></param> /// <param name="startFloor"></param> /// <param name="endFloor"></param> /// <returns></returns> public RouteDto getPath(string startBuildingId, string endBuildingId, double startPercentX, double startPercentY, double endPercentX, double endPercentY, int startFloor, int endFloor) { using (var uow = new BlueprintUnitOfWork()) { _startBluePrint = uow.BluePrints.FirstOrDefault(b => b.Id == ObjectId.Parse(startBuildingId)); // The start cannot be null if (_startBluePrint == null) { return new RouteDto().pathfindingError(); } var startFloorPlan = _startBluePrint.Floorplans.FirstOrDefault(fp => fp.Floor == startFloor); var endFloorPlan = startFloorPlan; if (startBuildingId == endBuildingId && startFloor != endFloor) { endFloorPlan = _startBluePrint.Floorplans.FirstOrDefault(fp => fp.Floor == endFloor); } int startGridWidth = startFloorPlan.ImageDataWidth; int startGridHeight = startFloorPlan.ImageDataHeight; int endGridWidth = endFloorPlan.ImageDataWidth; int endGridHeight = endFloorPlan.ImageDataHeight; int startX = (int)(startGridWidth * startPercentX); int startY = (int)(startGridHeight * startPercentY); int endX = (int)(endGridWidth * endPercentX); int endY = (int)(endGridHeight * endPercentY); if (startBuildingId != endBuildingId) { _endBluePrint = uow.BluePrints.FirstOrDefault(b => b.Id == ObjectId.Parse(endBuildingId)); endFloorPlan = _endBluePrint.Floorplans.FirstOrDefault(fp => fp.Floor == endFloor); endGridWidth = endFloorPlan.ImageDataWidth; endGridHeight = endFloorPlan.ImageDataHeight; endX = (int)(endGridWidth * endPercentX); endY = (int)(endGridHeight * endPercentY); } // If the ending BluePrint is null, that only means that there is no second // building to navigate to. So we will just pathfind within the one building. if (_endBluePrint == null) { return new BlueprintPathfinder(uow, _startBluePrint).getPath(startX, startY, endX, endY, startFloorPlan, endFloorPlan); } //** The fun part! Here we will need to do a GPS (outdoor) transition between two buildings. **// // Get exit POIs for start and end buildings var startBldgExits = _startBluePrint.Floorplans .SelectMany(fp => fp.NavPois) .Where(poi => poi.Type == NavType.exit) .ToList(); var endBldgExits = _endBluePrint.Floorplans .SelectMany(fp => fp.NavPois) .Where(poi => poi.Type == NavType.exit) .ToList(); // var startBldgExits = _startBluePrint.NavigationalPois // .Where(poi => poi.Type == NavType.Exit) // .Select(poi => poi.Locations.FirstOrDefault()) // .ToList(); // var endBldgExits = _endBluePrint.NavigationalPois // .Where(poi => poi.Type == NavType.Exit) // .Select(poi => poi.Locations.FirstOrDefault()) // .ToList(); //** Get the distances between the exits of the buildings to find the closest ones **// double smallestDistance = Double.PositiveInfinity; NavPoi startLoc = null; NavPoi endLoc = null; foreach (var startNav in startBldgExits) { foreach (var endNav in endBldgExits) { double distance = GeoUtils.getDistance(startNav.Geotag[0], startNav.Geotag[1], endNav.Geotag[0], endNav.Geotag[1]); if (distance < smallestDistance) { smallestDistance = distance; startLoc = startNav; endLoc = endNav; } } } //** Add exit locations to list in order of priorty to consider for pathfinding **// var starts = new List<WeightedLocation>(); var ends = new List<WeightedLocation>(); // Floorplan for the navPoi Floorplan startNavFloorplan = _startBluePrint.GetFloorplanForNavPoi(startLoc.Id); Floorplan endNavFloorplan = _endBluePrint.GetFloorplanForNavPoi(endLoc.Id); // Set each possible start-exit location with a weight in relation to the ideal end-exit location foreach (var navPoi in startBldgExits) { double distance = GeoUtils.getDistance(navPoi.Geotag[0], navPoi.Geotag[1], endLoc.Geotag[0], endLoc.Geotag[1]); starts.Add(new WeightedLocation(navPoi.Location, distance, startNavFloorplan)); } // Set each possible end-exit location with a weight in relation to the ideal start-exit location foreach (var navPoi in endBldgExits) { double distance = GeoUtils.getDistance(navPoi.Geotag[0], navPoi.Geotag[1], startLoc.Geotag[0], startLoc.Geotag[1]); ends.Add(new WeightedLocation(navPoi.Location, distance, endNavFloorplan)); } // sort the lists into priority order according to weight starts.Sort((geo1, geo2) => geo1.Weight.CompareTo(geo2.Weight)); ends.Sort((geo1, geo2) => geo1.Weight.CompareTo(geo2.Weight)); //** Find valid routes from within each building to an exit **// WeightedLocation outidePathStarts = starts.First(); WeightedLocation outidePathEnds = ends.First(); var startPathFinder = new BlueprintPathfinder(uow, _startBluePrint); var endPathFinder = new BlueprintPathfinder(uow, _endBluePrint); RouteDto startRoute = null; RouteDto endRoute = null; // Get and validate the startPath foreach (WeightedLocation loc in starts) { startRoute = startPathFinder.getPath(startX, startY, (int)(loc.Location.X * startGridWidth), (int)(loc.Location.Y * startGridHeight), startFloorPlan, loc.Floorplan); if (startRoute != null && startRoute.code == RouteDto.CODE_SUCCESS) { startLoc.Location = loc.Location; break; } } if (startRoute == null) { return new RouteDto().pathfindingError(); } if (startRoute.code != RouteDto.CODE_SUCCESS) { return startRoute; } // Get and validate the end path foreach (WeightedLocation loc in ends) { endRoute = endPathFinder.getPath((int)(loc.Location.X * endGridWidth), (int)(loc.Location.Y * endGridHeight), endX, endY, loc.Floorplan, endFloorPlan); if (endRoute != null && endRoute.code == RouteDto.CODE_SUCCESS) { endLoc.Location = loc.Location; break; } } if (endRoute == null) { return new RouteDto().pathfindingError(); } if (endRoute.code != RouteDto.CODE_SUCCESS) { return endRoute; } // Get the Google path GoogJson resp = GoogleMapsApi.getDirections(startLoc.Geotag[0], startLoc.Geotag[1], endLoc.Geotag[0], endLoc.Geotag[1], GoogleMapsApi.MODE_WALKING); if (resp.Routes.FirstOrDefault() == null) { return new RouteDto().pathfindingError(); } RouteDto outdoorRoute = new RouteDto() .addOutdoorTransisiton(NavType.walking, new CoordinateDto((int)(startLoc.Location.X * startGridWidth), (int)(startLoc.Location.Y * startGridHeight), startPathFinder.lastFloorGridWidth, startPathFinder.lastFloorGridHeight), startNavFloorplan.Floor); outdoorRoute.addEvent( new RouteEvent() .setOutdoor(resp.Routes.FirstOrDefault().Overview_Polyline.Points, _startBluePrint.Id.ToString(), _endBluePrint.Id.ToString(), startLoc.Geotag[0], startLoc.Geotag[1], endLoc.Geotag[0], endLoc.Geotag[1])); return startRoute.append(outdoorRoute).append(endRoute); } }
/// <summary> /// Fullfills pathfinding requests by returning a Route object. /// </summary> /// <param name="startX"></param> /// <param name="endX"></param> /// <param name="startY"></param> /// <param name="endY"></param> /// <param name="startFloor"></param> /// <param name="endFloor"></param> /// <returns></returns> public RouteDto getPath(int startX, int startY, int endX, int endY, Floorplan startFloorPlan, Floorplan endFloorPlan) { int startFloor = startFloorPlan.Floor; int endFloor = endFloorPlan.Floor; // The route object will contain the final route, if one exists RouteDto route = new RouteDto(); if (_bluePrint == null) { return route.pathfindingError(); } // Get map of start floor through api. // If something goes wrong, return a fail-code route bool[,] startFloorMap = getFloorMap(startFloor, _bluePrint); if (startFloorMap == null) { return route.pathfindingError(); } // API call for endFloor map // (needed in places of different scope below) bool[,] endFloorMap = null; if (startFloor != endFloor) { endFloorMap = getFloorMap(endFloor, _bluePrint); if (endFloorMap == null) { return route.pathfindingError(); } } // BEGIN PATHFINDING ///////////////// if (startFloor == endFloor) { AStarSearch searchPath = new AStarSearch(startFloorMap).run(startX, startY, endX, endY); if (searchPath.hasSolution()) { // Create the event for the path and add it to our route lastFloorGridWidth = searchPath.gridLengthX; lastFloorGridHeight = searchPath.gridLengthY; return route.addPath(startFloor, searchPath.Solution.ToList()); } // falls out to third-tier search } else { if (endFloorMap == null) { return route.pathfindingError(); } // API call searching for all "vertical paths" (VPs) from startFloor directly to endFloor // var directPois = _bluePrint.NavigationalPois // .Where(v => v.Locations.Any(l => l.FloorPlan.Floor == startFloor) && v.Locations.Any(asd => asd.FloorPlan.Floor == endFloor)) // .ToList(); var directPois = _bluePrint.GetDirectNavPois(startFloor, endFloor); if (directPois != null && directPois.Count > 0) { // Create the search objs here to be reused. Prevents duplicatoin of weighted-grid work. AStarSearch search1 = new AStarSearch(startFloorMap); AStarSearch search2 = new AStarSearch(endFloorMap); // Here we are looking for a valid path using only one stairs, elevator, etc. foreach (var v in directPois) { // start floor var fp1 = v.Location; // FloorPlanLocation fp1 = v.Locations.Where(x => x.FloorPlan.Floor == startFloor).FirstOrDefault(); int vertX1 = (int) (fp1.X*startFloorPlan.ImageDataWidth); int vertY1 = (int) (fp1.Y*startFloorPlan.ImageDataHeight); // find path from user position to the "stairs" search1.run(startX, startY, vertX1, vertY1); // if we can't get to the "stairs" from here, lets try the next way up if (!search1.hasSolution()) { continue; } // end floor var fp2 = v.Location; // FloorPlanLocation fp2 = v.Locations.Where(x => x.FloorPlan.Floor == endFloor).FirstOrDefault(); int vertX2 = (int) (fp2.X*endFloorPlan.ImageDataWidth); int vertY2 = (int) (fp2.Y*endFloorPlan.ImageDataHeight); // find path from "stairs" to the ending position search2.run(vertX2, vertY2, endX, endY); // if we can't get to the "stairs" from here, we do not want to get to the return statement if (!search2.hasSolution()) { continue; } lastFloorGridWidth = search2.gridLengthX; lastFloorGridHeight = search2.gridLengthY; // Create solution return route .addPath(startFloor, search1.Solution.ToList()) .addVerticalTransisiton(v.Type, new CoordinateDto(vertX1, vertY1, search1.gridLengthX, search1.gridLengthY), startFloor, endFloor) .addPath(endFloor, search2.Solution.ToList()); } // falls out to third-tier search } } // the infamous third-tier search return route; }
public ActionResult SaveRoute(RouteDto dto) { if (String.IsNullOrWhiteSpace(dto.Name)) return this.Direct(new { success = false }); if (dto.Id == Guid.Empty.ToString()) dto.Id = new Guid().ToString(); return this.Direct(new { success = true, data = dto }); }
private Route CreateRoute(RouteDto dto) { return Route.Create(dto); }
public RouteViewModel(RouteDto route) { this.Name = route.Name; this.RouteNumber = route.RouteNumber; this.IsUpStop = route.IsUpStop; }