// Returns the number of webcams that can see us at our current location.
        // Is this method doing too much?
        public int ProcessGeoMarker(IGeoMarker geoMarker)
        {
            // Add the GeoMarker to the database and get the ID.
            var geoMarkerId = _location.AppendGeoMarker(geoMarker);

            // Get the list of webcams that we might be able to see us at our current location.
            var webCamsWithinWebCamRadiusOfVisibility =
                _location.GetWebCamsWithinWebCamRadiusOfVisibility(new Point
                                                                    {
                                                                        XCoord = geoMarker.XCoord,
                                                                        YCoord = geoMarker.YCoord
                                                                    });

            // If there are any webcams that can see us...
            if (webCamsWithinWebCamRadiusOfVisibility.Count > 0)
            {
                foreach (var webCam in webCamsWithinWebCamRadiusOfVisibility)
                {
                    using (var trans = new TransactionScope())
                    {
                        // Capture and add the image to the DB.
                        // Future modification - only capture an image if one has not been recently (within seconds) captured for that webcam.
                        // Future modification - remove this internal dependency on WebCamImage (make a factory?).
                        // Future modification - remove this internal dependency on AwsStorageServiceAgent (could be done using the IoC container?).
                        _webCamControl.WebCam = webCam;
                        _webCamControl.WebCamImage = new WebCamImage();
                        _webCamControl.CaptureCurrentImage(new WebCamDataRequest());
                        _webCamControl.CapturedImage = new CapturedImage();
                        var capturedImageId = _webCamControl.StoreCapturedImage();

                        // Map the image to the GeoMarker
                        // Refactor this method so that it takes a complex type, rather than two primitives.
                        _location.MapCapturedImageToGeoMarker(capturedImageId, geoMarkerId);

                        // commit the change
                        trans.Complete();
                    }
                }
            }

            // Return the count of images collected.
            return webCamsWithinWebCamRadiusOfVisibility.Count;
        }
        public IWebCamExtendedInfo GetNearestWebCam(IGeoMarker geoMarker)
        {
            // Generate distances for all camera locations from this point
            var webCamsWithDistanceFromGeoMarker =
                from webCam in _myBigBroRepository.Set<Infostructure.MyBigBro.DataModel.Models.WebCam>()
                select new WebCamExtendedInfo
                {
                    //_geometry.GetDistancePythagoras(webCam.XCoord, webCam.YCoord, geoMarker.XCoord, geoMarker.YCoord)
                    Distance = SqlFunctions.SquareRoot(SqlFunctions.Square(webCam.XCoord - geoMarker.XCoord) + SqlFunctions.Square(webCam.YCoord - geoMarker.YCoord)).Value,
                    Id = webCam.Id,
                    Name = webCam.Name,
                    RadiusOfVisibility = webCam.RadiusOfVisibility,
                    XCoord = webCam.XCoord,
                    YCoord = webCam.YCoord,
                    Url = webCam.Url
                };

            // Get the min distance
            var minDistance = webCamsWithDistanceFromGeoMarker.Min(cam => cam.Distance);

            // Select the camera with mon distance
            var webCamWithMinDistanceFromGeoMarker =
                from webCam in webCamsWithDistanceFromGeoMarker
                where webCam.Distance == minDistance
                select webCam;

            // Return it
            return webCamWithMinDistanceFromGeoMarker.First();
        }
        public IEnumerable<IWebCamExtendedInfo> GetNearestWebCams(int top, IGeoMarker geoMarker)
        {
            // Generate distances for all camera locations from this point
            // Need to do this using a loop as LINQ won't accept the "GetDistancePythagoras" otherwise.
            var webCamsWithDistanceFromGeoMarker = new List<WebCamExtendedInfo>();
            foreach (var webCam in _myBigBroRepository.Set<Infostructure.MyBigBro.DataModel.Models.WebCam>())
            {
                webCamsWithDistanceFromGeoMarker.Add(new WebCamExtendedInfo()
                {
                    Distance = _geometry.GetDistancePythagoras(webCam.XCoord, webCam.YCoord, geoMarker.XCoord, geoMarker.YCoord),
                    //Distance = SqlFunctions.SquareRoot(SqlFunctions.Square(webCam.XCoord - geoMarker.XCoord) + SqlFunctions.Square(webCam.YCoord - geoMarker.YCoord)).Value,
                    Id = webCam.Id,
                    Name = webCam.Name,
                    RadiusOfVisibility = webCam.RadiusOfVisibility,
                    XCoord = webCam.XCoord,
                    YCoord = webCam.YCoord,
                    Url = webCam.Url
                });
            }

            // Get the min distance
            var minDistance = webCamsWithDistanceFromGeoMarker.Min(cam => cam.Distance);

            // Select the camera with mon distance
            var webCamWithMinDistanceFromGeoMarker =
                from webCam in webCamsWithDistanceFromGeoMarker
                orderby webCam.Distance
                select webCam;

            // Return it
            return webCamWithMinDistanceFromGeoMarker.Take(top);
        }
Exemple #4
0
 public int AppendGeoMarker(IGeoMarker geoMarker)
 {
     _myBigBroRepository.Add<GeoMarker>((GeoMarker)geoMarker);
     _myBigBroRepository.SaveChanges();
     return geoMarker.Id;
 }