Exemplo n.º 1
0
        public IEnumerable <Beacon> GetBeaconsByCoordinate(double latitude, double longitude, int distance)
        {
            var coordinate = new GeoCoordinate(latitude, longitude);
            var repository = new BeaconRepository();

            return(repository.GetBeaconsByCoords(coordinate, distance));
        }
Exemplo n.º 2
0
        public bool PostBeacon(Beacon beacon, List <int> friends)
        {
            var beaconRepository = new BeaconRepository();
            var userRepository   = new UserRepository();
            var user             = userRepository.GetUser(beacon.UserId);

            userRepository.UpdateFriends(user, friends);
            beacon.StartTime = DateTime.Now;
            return(beaconRepository.PlaceBeacon(beacon));
        }
        public User GetUserByBeacon(int id)
        {
            var beaconRepository = new BeaconRepository();
            var userRepository   = new UserRepository();
            var beacon           = beaconRepository.GetBeacon(id);

            if (beacon == null)
            {
                return(null);
            }
            return(userRepository.GetUser(beacon.UserId));
        }
Exemplo n.º 4
0
        //public async Task<List<DiscoverListElement>> GetElementsToShow(EstimoteZoneEvent @event, Implementation currentImplementation, Sector currentSector)
        //{
        //    if (@event.EventType != EstimoteZoneEventTypes.EXIT)
        //    {
        //        Beacon beacon = new Beacon
        //        {
        //            Id = @event.Beacon.DeviceId,
        //            Uuid = @event.Beacon.Uuid,
        //            Major = @event.Beacon.Major,
        //            Minor = @event.Beacon.Minor
        //        };

        //        BeaconRepository beaconRepository = new BeaconRepository();

        //        // get the current implementation
        //        Implementation detectedImplementation = await beaconRepository.GetImplementation(beacon.Id);

        //        // whether the user enters to a diferent implementation than the current one
        //        if (currentImplementation == null || (currentImplementation != null && currentImplementation.Id != detectedImplementation.Id))
        //        {
        //            // change color and logo

        //            // save the implementation in the database
        //            ImplementationRepository implementationRepository = new ImplementationRepository();
        //            await implementationRepository.ReplaceImplementation(detectedImplementation);

        //            // returns new elements from the server
        //            return await manager.GetElements(beacon);
        //        }
        //        // whether the user stays inside the same implementation
        //        else
        //        {
        //            return await GetElementsToShow(beacon, currentSector);
        //        }
        //    }
        //    else
        //    {
        //        return currentElements;
        //    }
        //}

        public async Task <Sector> GetSector(EstimoteZoneEvent @event, Sector currentSector)
        {
            BeaconRepository beaconRepository = new BeaconRepository();

            Beacon beacon = new Beacon
            {
                Id    = @event.Beacon.DeviceId,
                Uuid  = @event.Beacon.Uuid,
                Major = @event.Beacon.Major,
                Minor = @event.Beacon.Minor
            };

            // get the current implementation
            Implementation detectedImplementation = await beaconRepository.GetImplementation(beacon.Id);

            if (detectedImplementation == null)
            {
                return(null);
            }

            if (@event.EventType != EstimoteZoneEventTypes.EXIT)
            {
                // get the current sector
                Sector detectedSector = await beaconRepository.GetSector(beacon.Id);

                // whether the user enters to a diferent sector than the current one
                if (currentSector == null || detectedSector == null || (currentSector != detectedSector))
                {
                    // update the current sector
                    return(detectedSector);

                    // returns new elements from the server
                    //return await manager.GetElements(beacon);
                }
                // whether the user stays inside the same sector
                else
                {
                    // returns the current list of elements
                    //return this.currentElements;
                    return(currentSector);
                }
            }
            else
            {
                return(currentSector);
            }
        }
Exemplo n.º 5
0
        public UserTests()
        {
            // create database
            DatabaseContext dbContext = CreateEmptyDatabase();

            this.azureService = new AzureServiceMock();

            this.userRepository = new UserRepository(dbContext);
            this.userService    = new UserService(this.userRepository);

            this.beaconRepository = new BeaconRepository(dbContext);
            this.beaconService    = new BeaconService(this.beaconRepository);

            this.eventRepository = new EventRepository(dbContext);
            this.eventService    = new EventService(this.eventRepository, this.userRepository, this.azureService);

            // create user controller
            this.userController = new UserController(this.userService, this.beaconService, this.eventService);
        }
Exemplo n.º 6
0
        //private async Task<List<DiscoverListElement>> GetElementsToShow(Beacon beacon, Sector currentSector)
        //{
        //    BeaconRepository beaconRepository = new BeaconRepository();

        //    // get the current sector
        //    Sector detectedSector = await beaconRepository.GetSector(beacon.Major, beacon.Minor);

        //    // whether the user enters to a diferent sector than the current one
        //    if (currentSector == null || (currentSector != null && currentSector != detectedSector))
        //    {
        //        // update the current sector
        //        currentSector = detectedSector;

        //        // returns new elements from the server
        //        return await manager.GetElements(beacon);
        //    }
        //    // whether the user stays inside the same sector
        //    else
        //    {
        //        // returns the current list of elements
        //        return this.currentElements;
        //    }
        //}

        public async Task <Sector> GetSector(Beacon beacon, Sector currentSector)
        {
            BeaconRepository beaconRepository = new BeaconRepository();

            // get the current sector
            Sector detectedSector = await beaconRepository.GetSector(beacon.Id);

            // whether the user enters to a diferent sector than the current one
            if (currentSector == null || (currentSector != null && currentSector != detectedSector))
            {
                // update the current sector
                return(detectedSector);

                // returns new elements from the server
                //return await manager.GetElements(beacon);
            }
            // whether the user stays inside the same sector
            else
            {
                // returns the current list of elements
                //return this.currentElements;
                return(currentSector);
            }
        }
Exemplo n.º 7
0
        public async Task <Implementation> ChangeImplementation(EstimoteZoneEvent @event, Implementation currentImplementation)
        {
            if (@event.EventType == EstimoteZoneEventTypes.EXIT)
            {
                // pedir elementos del beacon virtual
                // una mejora es que aqui se muestren las recomendaciones obtenidas de ML
                // tambien se podría mostrar un mapa con las zonas aupar mas cercanas

                // save the implementation in the database
                ImplementationRepository implementationRepository = new ImplementationRepository();
                await implementationRepository.DeleteImplementation();

                return(null);
            }
            else
            {
                Beacon beacon = new Beacon
                {
                    Id    = @event.Beacon.DeviceId,
                    Uuid  = @event.Beacon.Uuid,
                    Major = @event.Beacon.Major,
                    Minor = @event.Beacon.Minor
                };

                BeaconRepository beaconRepository = new BeaconRepository();

                // get the current implementation
                Implementation detectedImplementation = await beaconRepository.GetImplementation(beacon.Id);

                // whether the user enters to a diferent implementation than the current one
                if (currentImplementation == null || detectedImplementation == null || (currentImplementation != null && currentImplementation.Id != detectedImplementation.Id))
                {
                    // get the new implementation from the server
                    var newImplementation = await manager.GetImplementation(beacon);

                    // save the implementation in the database
                    ImplementationRepository implementationRepository = new ImplementationRepository();
                    await implementationRepository.ReplaceImplementation(newImplementation);

                    var scanner = DependencyService.Get <IProximityScanner>();

                    // stop observing proximity zones
                    scanner.StopObservingZones();

                    // dispose and delete custom proximity zones of the estimote proximity observer
                    scanner.ClearProximityZones();

                    // add new zones
                    newImplementation.ProximityZones.ForEach(x => scanner.AddCustomZone(x.Distance, Helpers.Settings.CustomProximityZoneKey, Helpers.Settings.CustomProximityZoneValue, x.Sectors.SelectMany(s => s.Beacons).Select(b => b.Id).ToArray()));

                    // start observing the new proximity zones and old ones
                    scanner.StartObservingZones();

                    return(newImplementation);
                }
                else
                {
                    return(currentImplementation);
                }
            }
        }
Exemplo n.º 8
0
        public bool PutBeacon(int id, int drinks)
        {
            var repository = new BeaconRepository();

            return(repository.PutBeacon(id, drinks));
        }
Exemplo n.º 9
0
        public bool DeleteBeacon(int id)
        {
            var repository = new BeaconRepository();

            return(repository.DeleteBeacon(id));
        }
Exemplo n.º 10
0
        public Beacon GetBeaconById(int id)
        {
            var repository = new BeaconRepository();

            return(repository.GetBeacon(id));
        }
Exemplo n.º 11
0
        public IEnumerable <Beacon> GetBeacons()
        {
            var repository = new BeaconRepository();

            return(repository.GetBeacons());
        }
 public BeaconService(IDatabaseRepository <Beacon> beaconRepository)
 {
     this.beaconRepository = (BeaconRepository)beaconRepository;
 }