コード例 #1
0
        private async Task SaveTrackMap()
        {
            if (String.IsNullOrEmpty(_trackName))
            {
                return;
            }

            try
            {
                var model = await _trackMapRepo.GetTrackMapInfoAsync(_trackName);

                if (model == null)
                {
                    model = new TrackMapInfo()
                    {
                        Latitude  = _telemetryCenterX,
                        Longitude = _telemetryCenterY,
                        TrackName = _trackName,
                        Zoom      = _mapZoom,
                        Size      = new Size(640, 640)
                    };
                    model.Url = _mapService.GetMapUri((float)model.Latitude, (float)model.Longitude, model.Zoom);
                }
                else
                {
                    model.Latitude  = _telemetryCenterX;
                    model.Longitude = _telemetryCenterY;
                    model.TrackName = _trackName;
                    model.Zoom      = _mapZoom;
                    model.Size      = new Size(640, 640);
                    model.Url       = _mapService.GetMapUri((float)model.Latitude, (float)model.Longitude, model.Zoom);
                }

                model = await _trackMapRepo.SaveTrackMapInfoAsync(model);

                await _trackMapRepo.SaveChangesAsync();

                var trackImageBytes = await _mapService.GetMapAsync((float)model.Latitude, (float)model.Longitude, model.Zoom);

                var trackImage = _mapService.GetImageFromBytes(trackImageBytes);

                await _trackMapRepo.SaveTrackMapImageAsync(trackImage, model.Id);

                await _trackMapRepo.SaveChangesAsync();

                MessageBox.Show("Track map info saved");
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }
コード例 #2
0
        protected virtual TrackMapInfo SaveTrackMapInfo(TrackMapInfo trackMapInfo)
        {
            var existing = GetTrackMapInfo(trackMapInfo.Id);

            if (existing != null)
            {
                DeleteTrackMapInfo(existing);
            }
            else
            {
                if (trackMapInfo.Id <= 0)
                {
                    trackMapInfo.Id = GetNextId();
                }
            }

            TrackMapInfos.Add(trackMapInfo);

            return(trackMapInfo);
        }
コード例 #3
0
        protected async Task DisplayTrackMap(TrackMapInfo trackMapInfo)
        {
            try
            {
                if (_loading)
                {
                    return;
                }

                if (trackMapInfo == null)
                {
                    return;
                }

                TrackMapImage = await _trackMapRepo.GetTrackMapImageAsync(trackMapInfo.Id);
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }
コード例 #4
0
 public async Task <TrackMapInfo> SaveTrackMapInfoAsync(TrackMapInfo trackMapInfo)
 {
     return(await Task.Run(() => SaveTrackMapInfo(trackMapInfo)));
 }
コード例 #5
0
 public string GetTrackMapImageFileName(TrackMapInfo trackMapInfo)
 {
     return(Path.Combine(_options.TracksDirectory, $"{trackMapInfo.Id}-{trackMapInfo.TrackName}.png"));
 }
コード例 #6
0
        protected virtual bool DeleteTrackMapInfo(TrackMapInfo trackMapInfo)
        {
            TrackMapInfos.Remove(trackMapInfo);

            return(true);
        }