示例#1
0
        private void LoadNearestStations()
        {
            if (nearestLazyBlock != null)
            {
                nearestLazyBlock.Cancel();
            }

            var lazyBlockUI = new LazyBlockUI <Tuple <double, Station> >(this, nearestStations, nearestStationsMessageTextBlock, null);

            LatLong from;

            if (fromStation == null)
            {
                var currentPosition = LocationService.CurrentPosition;
                if (!Settings.GetBool(Setting.LocationServicesEnabled))
                {
                    lazyBlockUI.SetItems(null);
                    lazyBlockUI.SetLocalProgressMessage("Locations Services are disabled.\nYou can enable them in the Settings.");
                    nearestLazyBlock = null;
                    return;
                }
                else if (currentPosition == null || currentPosition.IsUnknown)
                {
                    lazyBlockUI.SetLocalProgressMessage("Acquiring position...");
                    lazyBlockUI.SetGlobalProgressMessage("Acquiring position...");
                    nearestLazyBlock = null;
                    return;
                }
                from = LatLong.Create(currentPosition.Latitude, currentPosition.Longitude);
            }
            else
            {
                from = fromStation.Location;
            }

            lazyBlockUI.SetLocalProgressMessage("");
            lazyBlockUI.SetGlobalProgressMessage("");

            nearestLazyBlock = new LazyBlock <Tuple <double, Station>[]>(
                "nearest stations",
                "No nearby stations",
                Stations.GetNearestAsync(from, 150),
                items => items.Length == 0,
                lazyBlockUI,
                false,
                null,
                null,
                nearestUnfiltered =>
            {
                var nearestFiltered = nearestUnfiltered.AsEnumerable();
                if (fromStation != null)
                {
                    nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != fromStation.Code);
                }
                if (excludeStation != null)
                {
                    nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != excludeStation);
                }
                return(nearestFiltered.ToArray());
            });
        }