Example #1
0
        public async Task <IDictionary <Guid, StationViewModel> > CreateViewModelsAsync(BikeShareNetwork bikeShare)
        {
            var vmDict = new Dictionary <Guid, StationViewModel>();

            await Task.Factory.StartNew(() =>
            {
                foreach (var station in bikeShare.Stations)
                {
                    var vm = StationViewModel.Create(station);
                    vmDict.Add(station.Id, vm);
                }
            });

            return(vmDict);
        }
Example #2
0
        public void SelectStation(StationViewModel station)
        {
            StationViewModel oldStation = this.CurrentStation;

            if (oldStation != null)
            {
                oldStation.DetailsVisibility = Visibility.Collapsed;
            }

            if (station != null)
            {
                // stupid hack to fix zorder
                this.StationSource.Remove(station);
                this.StationSource.Add(station);

                station.DetailsVisibility = Visibility.Visible;
            }

            this.CurrentStation = station;
        }
Example #3
0
        public static StationViewModel Create(BikeShareStation bikeShareStation)
        {
            var vm = new StationViewModel();

            vm.Id             = bikeShareStation.Id;
            vm.name           = bikeShareStation.Extra.Name;
            vm.bikeCount      = bikeShareStation.FreeBikes;
            vm.emptyDockCount = bikeShareStation.EmptySlots;
            vm.Locked         = bikeShareStation.Extra.Locked;
            vm.Installed      = bikeShareStation.Extra.Installed;
            vm.location       = new Geopoint(
                new BasicGeoposition {
                Latitude = bikeShareStation.Latitude, Longitude = bikeShareStation.Longitude
            });

            vm.CalcPieArc(vm.BikeCount, vm.EmptyDockCount);
            vm.DetermineAvailability();

            return(vm);
        }
Example #4
0
        private bool StationSourceFilter(StationViewModel station)
        {
            if (station == null)
            {
                return(false);
            }

            var myCity = Cities.CurrentCity;

            if (myCity == null)
            {
                return(false);
            }

            if (GeoUtil.DistanceTo(station.Location.Position, myCity.Center) < 50000)
            {
                return(true);
            }

            return(false);
        }
Example #5
0
        public void Update(StationViewModel other)
        {
            if (this.Id != other.Id)
            {
                Debug.Assert(false, "Station Id Mismatch.");
                return;
            }

            bool recalcPie = false;

            if (this.BikeCount != other.BikeCount)
            {
                this.BikeCount = other.BikeCount;
                recalcPie      = true;
            }

            if (this.EmptyDockCount != other.EmptyDockCount)
            {
                this.EmptyDockCount = other.EmptyDockCount;
                recalcPie           = true;
            }

            if (this.Locked != other.Locked)
            {
                this.Locked = other.Locked;
                recalcPie   = true;
            }

            if (this.Installed != other.Installed)
            {
                this.Installed = other.Installed;
                recalcPie      = true;
            }

            if (recalcPie)
            {
                this.CalcPieArc(bikeCount, emptyDockCount);
                this.DetermineAvailability();
            }
        }
Example #6
0
        private void SelectNearestStationWithAvailablilty(Predicate <StationViewModel> condition)
        {
            double           minDist        = Double.MaxValue;
            StationViewModel nearestStation = null;

            foreach (var station in this.StationSource)
            {
                double dist = GeoUtil.DistanceTo(myLocation.Position, station.Location.Position);
                if (dist < minDist && condition(station))
                {
                    nearestStation = station;
                    minDist        = dist;
                }
            }

            this.SelectStation(nearestStation);

            if (nearestStation != null)
            {
                this.MapCenter = nearestStation.Location;
            }
        }