Example #1
0
        public void SortBeaconsBasedOnDistance()
        {
            if (BeaconDetailsCollection.Count > 1)
            {
                bool wasChanged = true;

                while (wasChanged)
                {
                    wasChanged = false;

                    for (int i = 0; i < BeaconDetailsCollection.Count - 1; ++i)
                    {
                        if (BeaconDetailsCollection[i + 1].Distance < BeaconDetailsCollection[i].Distance ||
                            (BeaconDetailsCollection[i + 1].Distance == BeaconDetailsCollection[i].Distance &&
                             BeaconDetailsCollection[i + 1].Timestamp < BeaconDetailsCollection[i].Timestamp))
                        {
                            BeaconDetailsItem temp = BeaconDetailsCollection[i];
                            BeaconDetailsCollection[i]     = BeaconDetailsCollection[i + 1];
                            BeaconDetailsCollection[i + 1] = temp;
                            wasChanged = true;
                        }
                    }
                }
            }
        }
Example #2
0
        public async void AddOrReplace(Beacon beacon)
        {
            bool updated = false;

            for (int i = 0; i < BeaconDetailsCollection.Count; ++i)
            {
                if (BeaconDetailsCollection[i].Matches(beacon))
                {
                    BeaconDetailsCollection[i].Update(beacon);
                    updated = true;
                    break;
                }
            }

            if (!updated)
            {
                BeaconDetailsItem item = new BeaconDetailsItem(beacon);
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                                                                                                            BeaconDetailsCollection.Add(item));

                if (_updateBeaconTimesTimer == null)
                {
                    _updateBeaconTimesTimer = new Timer(UpdateBeaconTimesAsync, null, 1000, 1000);
                }
            }
        }