コード例 #1
0
        public async void BeaconEngine_Discovered(BluetoothLEAdvertisementReceivedEventArgs args)
        {
            //System.Diagnostics.Debug.WriteLine("Found Beacon : " + args.BluetoothAddress);

            //the test is progressing, so we do minimun amount of work here
            //and simply mark the beacon we got as seen during this test cycle
            if (_periodicTimer != null)
            {
                foreach (Beacon beacon in tmpCollection)
                {
                    if (beacon.BluetoothAddress == args.BluetoothAddress)
                    {
                        if (_listeningCycleCounter < beacon.DiscoveryTestData.Length)
                        {
                            beacon.DiscoveryTestData[_listeningCycleCounter] = true;
                            return;
                        }
                    }
                }
                //if it was some beacon we do not have in our list, then we simply ignore it
                return;
            }

            //beaconlist is only updated while we are not doing test
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                Beacon beacon = BeaconFactory.BeaconFromBluetoothLEAdvertisementReceivedEventArgs(args);
                if (beacon == null)
                {
                    return;
                }

                bool existingBeaconUpdated = false;

                foreach (Beacon existingBeacon in BeaconCollection)
                {
                    if (existingBeacon.Update(beacon))
                    {
                        existingBeaconUpdated = true;
                        beacon.Dispose();
                    }
                }

                if (!existingBeaconUpdated)
                {
                    BeaconCollection.Add(beacon);
                }
            });
        }