Beispiel #1
0
        public async Task Initialize(IEnumerable <TrackSectorViewModel> sectorCoordinates)
        {
            if (isTiming)
            {
                throw new InvalidOperationException("Cannot initialize LapTimer while it is already running. Please stop timing first.");
            }

            isTiming       = false;
            isFirstReading = true;

            if (geolocator != null)
            {
                geolocator.StatusChanged      -= geolocator_StatusChanged;
                geolocator.UnrecoverableError -= geolocator_UnrecoverableError;
                geolocator.Dispose();
            }

            this.sectorCoordinates = sectorCoordinates ?? Enumerable.Empty <TrackSectorViewModel>();
            if (this.sectorCoordinates.Any())
            {
                generateSectors   = false;
                lastSectorNumber  = this.sectorCoordinates.Max(s => s.SectorNumber);
                firstSectorNumber = this.sectorCoordinates.Min(s => s.SectorNumber);
            }
            else
            {
                generateSectors   = true;
                lastSectorNumber  = 1;
                firstSectorNumber = 1;
            }
            lapNumber           = 1;
            lapStartElapsedTime = TimeSpan.Zero;
            stopwatch           = new Stopwatch();
            geolocator          = await geolocatorFactory.GetGeolocator();

            geolocator.DesiredAccuracy     = PositionAccuracy.High;
            geolocator.MovementThreshold   = 1;
            geolocator.StatusChanged      += geolocator_StatusChanged;
            geolocator.UnrecoverableError += geolocator_UnrecoverableError;
        }