Exemple #1
0
        public async Task ImportSnapshotsAsync(Location locationToImport,
                                               Location importedLocation,
                                               CancellationToken cancellationToken)
        {
            var snapshotsToImport = await _snapshotService.GetSnapshotsByLocationIdAsync(locationToImport.Id);

            var remoteSnapshots = await _snapshotServiceProxy.GetSnapshotsByLocationIdAsync(importedLocation.Id);

            foreach (var snapshotToImport in snapshotsToImport)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (remoteSnapshots.Any(_ => _.PictureFileName == snapshotToImport.PictureFileName))
                {
                    continue;
                }

                var pictureToImport = await _pictureService.GetSnapshotContentAsync(snapshotToImport);

                if (pictureToImport.Length == 0)
                {
                    continue;
                }
                snapshotToImport.LocationId = importedLocation.Id;
                await _snapshotServiceProxy.AddSnapshotAsync(snapshotToImport);

                await _pictureServiceProxy.SaveSnapshotContentAsync(snapshotToImport, pictureToImport);
            }
        }
Exemple #2
0
        public async Task <IActionResult> AddSnapshot([FromBody] LocationSnapshotForCreationDto snapshotForCreation)
        {
            if (!ModelState.IsValid)
            {
                _logger.LogWarning("Bad request. Model state invalid: {@ModelState}", ModelState);
                return(BadRequest(ModelState));
            }

            var snapshotToAdd = Mapper.Map <LocationSnapshotForCreationDto, LocationSnapshot>(snapshotForCreation);
            var addedSnapshot = await _locationSnapshotDataService.AddSnapshotAsync(snapshotToAdd);

            var result = Mapper.Map <LocationSnapshot, LocationSnapshotDto>(addedSnapshot);

            return(Ok(result));
        }
Exemple #3
0
        public async Task OnCaptureSnapshot()
        {
            IsBusy = true;
            var pictureData = await _cameraService.CapturePhotoWithOrientationAsync();

            var now              = DateTime.Now.ToString("yyyyMMdd_HH_mm_ss");
            var pictureFileName  = $"LocationCapture_{now}.jpg";
            var locationSnapshot = new LocationSnapshot
            {
                LocationId      = GetLocationId(),
                PictureFileName = pictureFileName,
                Longitude       = double.MinValue,
                Latitude        = double.MinValue,
                Altitude        = double.MinValue,
                DateCreated     = DateTime.Now
            };

            var newSnapshot = await _locationSnapshotDataService.AddSnapshotAsync(locationSnapshot);

            await _pictureService.SaveSnapshotContentAsync(newSnapshot, pictureData);

            IsBusy = false;

            var locationDescriptor = await _locationService.GetCurrentLocationAsync();

            if (!(await _locationSnapshotDataService.GetSnapshotsByIdsAsync(new[] { newSnapshot.Id })).Any())
            {
                return;
            }
            newSnapshot.Longitude = locationDescriptor.Longitude;
            newSnapshot.Latitude  = locationDescriptor.Latitude;
            newSnapshot.Altitude  = locationDescriptor.Altitude;
            await _locationSnapshotDataService.UpdateSnapshotAsync(newSnapshot);

            _eventAggregator.GetEvent <GeolocationReadyEvent>().Publish(locationDescriptor);
        }
        public async void OnCaptureSnapshot_ShouldSucceed()
        {
            // Arrange
            SetUp();
            var navParam = new SnapshotsViewNavParams
            {
                SnapshotsIdsource = new Location {
                    Id = 2
                }
            };
            var locDescriptor = new LocationDescriptor
            {
                Longitude = 1,
                Latitude  = 2,
                Altitude  = 3
            };
            LocationSnapshot   newSnapshot     = null;
            LocationDescriptor receivedLocDesc = null;

            _locationSnapshotDataService.AddSnapshotAsync(Arg.Any <LocationSnapshot>())
            .Returns(_ =>
            {
                var snapshot = _.Arg <LocationSnapshot>();
                var tcs      = new TaskCompletionSource <LocationSnapshot>();
                tcs.SetResult(snapshot);
                return(tcs.Task);
            });
            _pictureService.SaveSnapshotContentAsync(Arg.Any <LocationSnapshot>(), Arg.Any <byte[]>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <int>();
                tcs.SetResult(0);
                return(tcs.Task);
            });
            _locationService.GetCurrentLocationAsync()
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <LocationDescriptor>();
                tcs.SetResult(locDescriptor);
                return(tcs.Task);
            });
            _locationSnapshotDataService.GetSnapshotsByIdsAsync(Arg.Any <IEnumerable <int> >())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <IEnumerable <LocationSnapshot> >();
                tcs.SetResult(new List <LocationSnapshot> {
                    new LocationSnapshot()
                });
                return(tcs.Task);
            });
            _locationSnapshotDataService.AddSnapshotAsync(Arg.Any <LocationSnapshot>())
            .Returns(_ =>
            {
                newSnapshot = _.Arg <LocationSnapshot>();
                var tcs     = new TaskCompletionSource <LocationSnapshot>();
                tcs.SetResult(newSnapshot);
                return(tcs.Task);
            });
            _eventAggregator.GetEvent <GeolocationReadyEvent>().Subscribe(_ => receivedLocDesc = _);

            // Act
            var sit = CreateViewModel();

            sit.NavigationParam = navParam;
            await sit.OnCaptureSnapshot();

            // Assert
            Assert.Equal(((Location)navParam.SnapshotsIdsource).Id, newSnapshot.LocationId);
            Assert.True(newSnapshot.PictureFileName.StartsWith("LocationCapture_") &&
                        newSnapshot.PictureFileName.EndsWith(".jpg"));
            Assert.Equal(locDescriptor.Longitude, newSnapshot.Longitude);
            Assert.Equal(locDescriptor.Latitude, newSnapshot.Latitude);
            Assert.Equal(locDescriptor.Altitude, newSnapshot.Altitude);
            Assert.Equal(newSnapshot.PictureFileName.Substring(16, 17), newSnapshot.DateCreated.ToString("yyyyMMdd_HH_mm_ss"));
            Assert.Equal(locDescriptor, receivedLocDesc);
        }