protected override async Task StartListeningAsync()
        {
            await base.StartListeningAsync();

            SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() =>
            {
                if (Beacons.Count > 0)
                {
                    _proximityObserver = new ProximityObserver(new CloudCredentials(EstimoteCloudAppId, EstimoteCloudAppToken), error =>
                    {
                        SensusServiceHelper.Get().Logger.Log("Error while initializing proximity observer:  " + error, LoggingLevel.Normal, GetType());
                    });

                    List <ProximityZone> beaconZones = new List <ProximityZone>();

                    foreach (EstimoteBeacon beacon in Beacons)
                    {
                        ProximityZone beaconZone = new ProximityZone(beacon.Tag, new ProximityRange(beacon.ProximityMeters))
                        {
                            OnEnter = async(triggeringDeviceAttachment) =>
                            {
                                await StoreDatumAsync(new EstimoteBeaconDatum(DateTimeOffset.UtcNow, beacon, EstimoteBeaconProximityEvent.Entered));
                            },

                            OnExit = async(triggeringDeviceAttachment) =>
                            {
                                await StoreDatumAsync(new EstimoteBeaconDatum(DateTimeOffset.UtcNow, beacon, EstimoteBeaconProximityEvent.Exited));
                            }
                        };

                        beaconZones.Add(beaconZone);
                    }

                    _proximityObserver.StartObservingZones(beaconZones.ToArray());
                }

                if (Location != null)
                {
                    EILRequestFetchLocation locationFetchRequest = new EILRequestFetchLocation(Location.Identifier);

                    locationFetchRequest.SendRequest((fetchedLocation, error) =>
                    {
                        if (error == null)
                        {
                            _foregroundIndoorLocationManager.StartPositionUpdatesForLocation(fetchedLocation);
                            _backgroundIndoorLocationManager.StartPositionUpdatesForLocation(fetchedLocation);
                            _indoorLocation = fetchedLocation;
                        }
                        else
                        {
                            SensusServiceHelper.Get().Logger.Log("Failed to fetch Estimote indoor location:  " + error, LoggingLevel.Normal, GetType());
                        }
                    });
                }
            });
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // get your app ID and token on:
            // https://cloud.estimote.com/#/apps/add/your-own-app
            var creds = new CloudCredentials("app ID", "app token");

            observer = new ProximityObserver(creds, (error) =>
            {
                Debug.WriteLine($"error = {error}");
            });

            var range = new ProximityRange(1.0);

            var zone1 = new ProximityZone("lobby", range)
            {
                OnEnter = (context) =>
                {
                    Debug.WriteLine($"zone1 enter, context = {context}");
                },
                OnExit = (context) =>
                {
                    Debug.WriteLine($"zone1 exit, context = {context}");
                },
                OnContextChange = (contexts) =>
                {
                    Debug.WriteLine($"zone1 contextChange, contexts = {contexts}");
                }
            };

            var zone2 = new ProximityZone("conf-room", range)
            {
                OnEnter = (context) =>
                {
                    Debug.WriteLine($"zone2 enter, context = {context}");
                },
                OnExit = (context) =>
                {
                    Debug.WriteLine($"zone2 exit, context = {context}");
                },
                OnContextChange = (contexts) =>
                {
                    Debug.WriteLine($"zone2 contextChange, contexts = {contexts}");
                }
            };

            observer.StartObservingZones(new ProximityZone[] { zone1, zone2 });

            Debug.WriteLine("Proximity all ready to go!");

            return(true);
        }
Beispiel #3
0
 // Se sobreescribe el metodo para que solo la primera vez que se suscriban
 // se cree lo necesario para que la lib de estimote escanee objetos.
 public override IDisposable Subscribe(IObserver <T> observer)
 {
     if (proximityZone == null)
     {
         this.proximityZone = this.estimoteProximityObserver
                              .zoneBuilder()
                              .forTag(this.tag)
                              .inCustomRange(base.distance)
                              .withOnEnterAction((ProximityContext, Unit) => {
             // Por cada objeto detectado, llamo a OnObjectDetecte para que publique el evento
             this.OnObjectDetected(EventType.OnEnter, ProximityContext.Id);
         })
                              .withOnExitAction((ProximityContext, Unit) => {
             // Por cada objeto detectado, llamo a OnObjectDetecte para que publique el evento
             this.OnObjectDetected(EventType.OnExit, ProximityContext.Id);
         })
                              .withOnChangeAction((ProximityContext[], Unit >) => {
             // Por cada objeto detectado, llamo a OnObjectDetecte para que publique el evento
             this.OnObjectDetected(EventType.OnChange, ProximityContext[0].Id);
         })