public static MessageDto AddFloorplanImage(int id, string base64, int pixelsPerFoot)
        {
            using (var uow = new BlueprintUnitOfWork())
            {
                var fp = uow.FloorPlans.Find(id);
                if (fp == null)
                {
                    return new MessageDto("Could not find floorplan");
                }
                if (!string.IsNullOrWhiteSpace(fp.CalibrationImagePath))
                {
                    return new MessageDto("Image already exists. Use PUT verb to update image.");
                }
                string path = fp.SaveImageToDisk(base64);
                string filename = path.Substring(path.LastIndexOf('/'));
                string datagridFile = fp.GetDataGridPath();
                fp.DataGridUrl = string.Format(Defs.DataGridUrl, datagridFile);
                fp.CalibrationImagePath = string.Format(Defs.ImageUrl, filename);
                fp.PixelsPerFoot = pixelsPerFoot;

                // Execute the script for image processing
                string dataGridFilePath = Defs.DataGridDirectory + datagridFile;
                var dto = ExecuteImageProcessorScript(path, fp.Id, pixelsPerFoot, dataGridFilePath);
                if (dto.Result)
                {
                    uow.Save();
                    return dto;
                }
                // If failed delete image
                File.Delete(path);
                return new MessageDto("An error occured while processing the image. The image was not saved.\n" + dto.Message);
            }
        }
 public static NavPoiDto GetVerticalPoi(int id)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var poi = uow.VerticalPois.Find(id);
         return poi.ToDto();
     }
 }
 public static IEnumerable<BluePrintDto> FindBluePrintsForRegion(string region)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var bps = uow.BluePrints.Where(b => b.Region == region).ToList().Select(bp => bp.ToDto()).ToList();
         return bps;
     }
 }
 public static BluePrintDto GetBluePrint(int id)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var bp = uow.BluePrints.Find(id);
         return bp.ToDto();
     }
 }
 static void Main(string[] args)
 {
     var uow = new BlueprintUnitOfWork();
     var coll = BaseContext._client.GetServer().GetDatabase("blueprint").GetCollection<Blueprint>("blueprints");
     var bp = coll.AsQueryable().Where(b => b.Id == ObjectId.Parse("533b580fb9471e5a4ffd5fc5")).ToList();
     var bps = uow.BluePrints.All();
     Console.ReadLine();
 }
Exemple #6
0
 public static PoiCollection FindPoiForBluePrint(int bluePrintId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var bp = uow.BluePrints.Find(bluePrintId);
         var bps = bp == null ? new List<PoiDto>() : bp.FloorPlans.SelectMany(f => f.PointsOfInterest.Select(p => p.ToDto())).ToList();
         return new PoiCollection{Result = true, Pois = bps};
     }
 }
 public static NavPoiDto CreateNavPoi(NavPoiRequestDto.NavPoiAdd post)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var poi = post.ToEntity();
         uow.Save();
         return poi.ToDto();
     }
 }
 public static IEnumerable<NavPoiDto> FindVerticalPoisForFloorplan(int floorplanId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var fp = uow.FloorPlans.Find(floorplanId);
         var pois = uow.VerticalPois.Where(v => v.Locations.All(l => l.FloorPlan.Id == fp.Id));
         return pois.Select(p => p.ToDto());
     }
 }
        public static BeaconDto GetBeacon(int id)
        {
            using (var uow = new BlueprintUnitOfWork())
            {
                var beacon = uow.Beacons.Where(b => b.Id == id).FirstOrDefault();

                return beacon == null ? null : beacon.ToDto();
            }
        }
 public static IEnumerable<NavPoiDto> FindVerticalPoisForBluePrint(int bluePrintId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var bp = uow.BluePrints.Find(bluePrintId);
         var vertPois = bp.NavigationalPois;
         return vertPois.Select(p => p.ToDto());
     }
 }
 public static BeaconCollection FindBeaconsForFloorplan(int floorPlanId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var fp = uow.FloorPlans.Find(floorPlanId);
         return fp == null
             ? new BeaconCollection {Result = false}
             : new BeaconCollection {Result = true, Beacons = fp.Beacons.Select(b => b.ToDto()).ToList()};
     }
 }
 public static IEnumerable<BluePrintDto> FindBluePrintsForUser(int userId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var user = uow.Users.Find(userId);
         return user == null
             ? new List<BluePrintDto>()
             : user.BluePrints
                 .Select(bp => bp.ToDto())
                 .OrderBy(b => b.LastModified).ToList();
     }
 }
Exemple #13
0
 public static PoiDto CreatePoi(PoiRequestDto.PointOfInterestAdd addPoi)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var fp = uow.FloorPlans.Find(addPoi.FloorPlanId);
         var poi = addPoi.ToEntity();
         fp.PointsOfInterest.Add(poi);
         poi.Location.FloorPlan = fp;
         uow.FloorPlanLocations.Add(poi.Location);
         uow.Save();
         return poi.ToDto();
     }
 }
 public static BeaconCollection FindBeaconsForBluePrint(int id)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var bp = uow.BluePrints.Where(b => b.Id == id).FirstOrDefault();
         if (bp == null)
         {
             return null;
         }
         var beacons = bp.FloorPlans.SelectMany(fp => fp.Beacons).ToList();
         return new BeaconCollection {Result = true, Beacons = beacons.Select(beacon => beacon.ToDto()).ToList()};
     }
 }
 public static MessageDto DeleteBeacon(int beaconId, int userId, int blueprintId, int floorplanId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var beacon = uow.Beacons.Where(b => b.Id == beaconId).FirstOrDefault();
         if (!IsBeaconOwner(beacon, userId, blueprintId, floorplanId))
         {
             return new MessageDto("Could not find beacon.");
         }
         uow.Beacons.Delete(beacon);
         uow.Save();
         return new MessageDto(true);
     }
 }
Exemple #16
0
 public static MessageDto DeletePoi(int poiId, int userId, int blueprintId, int floorplanId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var poi = uow.PointsOfInterest.Find(poiId);
         if (!IsPoiOwner(poi, userId, blueprintId, floorplanId))
         {
             return new MessageDto("Could not find point of interest.");
         }
         uow.PointsOfInterest.Delete(poi);
         uow.Save();
         return new MessageDto(true);
     }
 }
 public static MessageDto DeleteVertPoi(int poiId, int userId, int blueprintId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var vertpoi = uow.VerticalPois.Find(poiId);
         if (!IsVertPoiOwner(vertpoi, userId, blueprintId))
         {
             return new MessageDto("Could not find point of interest.");
         }
         uow.VerticalPois.Delete(vertpoi);
         uow.Save();
         return new MessageDto(true);
     }
 }
 public static MessageDto AddUpdateNavigationalPoiThumbnail(int id, string base64)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var poi = uow.VerticalPois.Find(id);
         if (poi == null)
         {
             return new MessageDto("Could not find point of interest.");
         }
         poi.ThumbnailPath = poi.SaveThumbnailToDisk(base64);
         uow.Save();
         return new MessageDto(true);
     }
 }
 public static MessageDto DeleteBlueprint(int blueprintId, int userId)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var bp = uow.BluePrints.Find(blueprintId);
         if (!IsBluePrintOwner(bp, userId))
         {
             return new MessageDto("Could not find blueprint.");
         }
         uow.BluePrints.Delete(bp);
         uow.Save();
         return new MessageDto(true);
     }
 }
Exemple #20
0
 public static MessageDto AddUpdatePoiThumbnail(int id, string base64)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var poi = uow.PointsOfInterest.Find(id);
         if (poi == null)
         {
             return new MessageDto("Could not find point of interest.");
         }
         var image = Convert.FromBase64String(base64);
         poi.ThumbnailPath = poi.SaveThumbnailToDisk(base64);
         uow.Save();
         return new MessageDto(true);
     }
 }
 public static MessageDto AddUpdateUserFloorPlanImage(int id, string base64, int pixelsPerFoot = Defs.PixelsPerFoot)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var fp = uow.FloorPlans.Find(id);
         if (fp == null)
         {
             return new MessageDto("Could not find floorplan.");
         }
         string path = fp.SaveImageToDisk(base64, true);
         string filename = path.Substring(path.LastIndexOf('/'));
         fp.UserImagePath = string.Format(Defs.ImageUrl, filename);
         uow.Save();
         return new MessageDto(true);
     }
 }
 public static FloorPlanDto CreateFloorPlan(FloorPlanRequestDto.FloorplanAdd addFp)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         // Ensure blueprint exists and a floorplan does not already exist on the same floor
         var bp = uow.BluePrints.Find(addFp.BluePrintId);
         if (bp == null || bp.FloorPlans.FirstOrDefault(f => f.Floor == addFp.Floor) != null)
         {
             return null;
         }
         var fp = addFp.ToEntity();
         bp.FloorPlans.Add(fp);
         uow.Save();
         return fp.ToDto();
     }
 }
        public static BluePrintDto CreateBluePrint(BluePrintRequestDtos.BluePrintAdd createDto)
        {
            using (var uow = new BlueprintUnitOfWork())
            {
                var user = uow.Users.Find(createDto.UserId);
                if (user == null ||
                    user.BluePrints.FirstOrDefault(b => b.Name == createDto.BluePrintName) != null)
                {
                    return null;
                }
                var bp = createDto.ToEntity();
                user.BluePrints.Add(bp);
                uow.Save();
                return bp.ToDto();

            }
        }
        public static BeaconDto AddBeacon(BeaconRequestDtos.BeaconAdd addDto)
        {
            using (var uow = new BlueprintUnitOfWork())
            {
                // Check if the floorplan exists and the beacon has not been added
                var fp = uow.FloorPlans.Where(b => b.Id == addDto.FloorPlanId).FirstOrDefault();
                if (fp == null)
                {
                    return null;
                }

                // Map to Beacon object
                var beacon = addDto.ToEntity();
                fp.Beacons.Add(beacon);
                uow.Save();
                return beacon.ToDto();
            }
        }
 public static MessageDto UpdateBluePrint(int id, string name, string country, string state, string city, string region)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var bp = uow.BluePrints.Find(id);
         if (bp == null)
         {
             return new MessageDto("Could not find blueprint.");
         }
         bp.Country = country;
         bp.City = city;
         bp.State = state;
         bp.Region = region;
         bp.Name = name;
         uow.Save();
         return new MessageDto(true);
     }
 }
Exemple #26
0
 private static void AddCalibImage(JsonServiceClient client)
 {
     var floorplans = new List<FloorPlan>();
     using (var uow = new BlueprintUnitOfWork())
     {
         floorplans = uow.FloorPlans.Where(f => f.BluePrintId == 1).ToList();
     }
     for (int i = 1; i <= 3; i++)
     {
         var path = string.Format(Laptop, i);
         Console.WriteLine("Path is " + path);
         var image = Image.FromFile(path);
         var dto = new FloorPlanRequestDto.FloorplanAddImage
         {
             FloorplanId = floorplans.FirstOrDefault(f => f.Floor == (i - 1)).Id,
             Image = Convert.ToBase64String(image.ImageToByteArray())
         };
         Console.WriteLine("Send request...");
         var resp = client.Post(dto);
         Console.WriteLine(resp.Message);
     }
     Console.WriteLine("done");
     Console.ReadLine();
 }
 public static MessageDto UpdateBeaconLocation(int id, double xPos, double yPos)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var beacon = uow.Beacons.Where(b => b.Id == id).FirstOrDefault();
         if (beacon == null)
         {
             return new MessageDto("Could not find beacon.");
         }
         beacon.Location.XPos = xPos;
         beacon.Location.YPos = yPos;
         uow.Save();
         return new MessageDto(true);
     }
 }
 public static MessageDto UpdateBeacon(int id, string name, string address, bool isNew = false)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var beacon = uow.Beacons.Where(b => b.Id == id).FirstOrDefault();
         if (beacon == null)
         {
             return new MessageDto("Could not find beacon.");
         }
         beacon.Name = name;
         beacon.Address = address;
         beacon.LastModified = DateTime.UtcNow;
         if (isNew)
         {
             beacon.InstallationDate = DateTime.UtcNow;
         }
         uow.Save();
         return new MessageDto(true);
     }
 }
 public static BeaconDto GetBeacon(string address)
 {
     using (var uow = new BlueprintUnitOfWork())
     {
         var beacon = uow.Beacons.Where(b => b.Address == address).FirstOrDefault();
         return beacon == null ? null : beacon.ToDto();
     }
 }
Exemple #30
0
        /// <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 startBuildingId, int endBuildingId, double startPercentX, double startPercentY, double endPercentX, double endPercentY, int startFloor, int endFloor)
        {
            using (BlueprintUnitOfWork uow = new BlueprintUnitOfWork())
            {
                _startBluePrint = uow.BluePrints.FirstOrDefault(b => b.Id == startBuildingId);

                // The start cannot be null
                if (_startBluePrint == null)
                {
                    return new RouteDto().pathfindingError();
                }

                FloorPlan startFloorPlan = _startBluePrint.FloorPlans.FirstOrDefault(fp => fp.Floor == startFloor);
                FloorPlan 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 == 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.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;
                FloorPlanLocation startLoc = null;
                FloorPlanLocation endLoc = null;

                foreach (FloorPlanLocation s in startBldgExits)
                {
                    foreach (FloorPlanLocation e in endBldgExits)
                    {
                        double distance = GeoUtils.getDistance(s.Latitude, s.Longitude, e.Latitude, e.Longitude);
                        if (distance < smallestDistance)
                        {
                            smallestDistance = distance;
                            startLoc = s;
                            endLoc = e;
                        }
                    }
                }

                //** Add exit locations to list in order of priorty to consider for pathfinding **//

                var starts = new List<WeightedLocation>();
                var ends = new List<WeightedLocation>();

                // Set each possible start-exit location with a weight in relation to the ideal end-exit location
                foreach (FloorPlanLocation loc in startBldgExits)
                {
                    double distance = GeoUtils.getDistance(loc.Latitude, loc.Longitude, endLoc.Latitude, endLoc.Longitude);
                    starts.Add(new WeightedLocation(loc, distance));
                }

                // Set each possible end-exit location with a weight in relation to the ideal start-exit location
                foreach (FloorPlanLocation loc in endBldgExits)
                {
                    double distance = GeoUtils.getDistance(loc.Latitude, loc.Longitude, startLoc.Latitude, startLoc.Longitude);
                    ends.Add(new WeightedLocation(loc, distance));
                }

                // 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();

                BluePrintPathFinder startPathFinder = new BluePrintPathFinder(uow, _startBluePrint);
                BluePrintPathFinder 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.XPos * startGridWidth), (int) (loc.location.YPos * startGridHeight), startFloorPlan, loc.location.FloorPlan);
                    if (startRoute != null && startRoute.code == RouteDto.CODE_SUCCESS)
                    {
                        startLoc = 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.XPos * endGridWidth), (int) (loc.location.YPos * endGridHeight), endX, endY, loc.location.FloorPlan, endFloorPlan);
                    if (endRoute != null && endRoute.code == RouteDto.CODE_SUCCESS)
                    {
                        endLoc = 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.Latitude, startLoc.Longitude, endLoc.Latitude, endLoc.Longitude, GoogleMapsApi.MODE_WALKING);

                if (resp.Routes.FirstOrDefault() == null)
                {
                    return new RouteDto().pathfindingError();
                }

                RouteDto outdoorRoute = new RouteDto()
                    .addOutdoorTransisiton(NavType.Walking, new CoordinateDto((int) (startLoc.XPos * startGridWidth), (int) (startLoc.YPos * startGridHeight), startPathFinder.lastFloorGridWidth, startPathFinder.lastFloorGridHeight), startLoc.FloorPlan.Floor);

                outdoorRoute.addEvent(
                    new RouteEvent()
                    .setOutdoor(resp.Routes.FirstOrDefault().Overview_Polyline.Points, _startBluePrint.Id, _endBluePrint.Id, startLoc.Latitude, startLoc.Longitude, endLoc.Latitude, endLoc.Longitude));

                return startRoute.append(outdoorRoute).append(endRoute);

            }
        }