public async Task <IActionResult> GetSnapshotsByIds( [ModelBinder(BinderType = typeof(IntArrayModelBinder), Name = "snapshotsIds")] IEnumerable <int> snapshotsIds) { if (snapshotsIds == null) { _logger.LogWarning("Bad request. Unable to deserialize snapshots IDs."); return(BadRequest()); } var snapshots = await _locationSnapshotDataService.GetSnapshotsByIdsAsync(snapshotsIds); var result = Mapper.Map <IEnumerable <LocationSnapshot>, IEnumerable <LocationSnapshotDto> >(snapshots); return(Ok(result)); }
public async Task OnLoaded() { IsBusy = true; var navParam = (SnapshotsViewNavParams)NavigationParam; _groupByCriteria = navParam.GroupByCriteria; var payload = navParam.SnapshotsIdsource; Parent = payload; IEnumerable <LocationSnapshot> snapshots = null; RaisePropertyChanged(nameof(CanAddSnapshot)); if (payload is Location location) { snapshots = await _locationSnapshotDataService.GetSnapshotsByLocationIdAsync(location.Id); } else if (payload is SnapshotGroup group) { snapshots = await _locationSnapshotDataService.GetSnapshotsByIdsAsync(group.SnapshotIds); } var miniatures = await _pictureService.GetSnapshotMiniaturesAsync(snapshots); foreach (var miniature in miniatures) { var thumbnail = await _bitmapConverter.GetBitmapAsync(miniature.Data); SnapshotThumbnails.Add(new SnapshotThumbnail { Snapshot = miniature.Snapshot, Thumbnail = thumbnail }); } IsBusy = false; }
public async Task <IActionResult> GetMiniatures( [ModelBinder(BinderType = typeof(IntArrayModelBinder), Name = "snapshotsIds")] IEnumerable <int> snapshotsIds) { if (snapshotsIds == null) { _logger.LogWarning("Bad request. Unable to deserialize snapshots IDs."); return(BadRequest()); } var results = new ArrayList(); IEnumerable <string> pictureFileNames = (await _locationSnapshotDataService.GetSnapshotsByIdsAsync(snapshotsIds)) .Select(_ => _.PictureFileName); foreach (var pictureFileName in pictureFileNames) { var picturePath = GetPictureFilePath(pictureFileName); if (PictureNotFound(picturePath)) { return(NotFound()); } var thumbnailBytes = await _imageService.GetThumbnailAsync(picturePath); var base64String = Convert.ToBase64String(thumbnailBytes); var snapshotMiniature = new { PictureFileName = pictureFileName, Thumbnail = base64String }; results.Add(snapshotMiniature); } return(Ok(results)); }
private void SetUp() { _snapshots = new List <LocationSnapshot> { new LocationSnapshot { PictureFileName = "Barcelona1.jpg" }, new LocationSnapshot { PictureFileName = "Prague1.jpg" }, new LocationSnapshot { PictureFileName = "Frankfurt1.jpg" } }; _miniatureData = new byte[] { 255, 216, 255 }; _pictureData = new byte[] { 224, 0, 16 }; _snapshotDataService = Substitute.For <ILocationSnapshotDataService>(); _snapshotDataService.GetSnapshotsByIdsAsync(Arg.Any <IEnumerable <int> >()) .Returns(_ => { var tcs = new TaskCompletionSource <IEnumerable <LocationSnapshot> >(); tcs.SetResult(_snapshots); return(tcs.Task); }); _fileSystemService = Substitute.For <IFileSystemService>(); _fileSystemService.FileExisits(Arg.Any <string>()) .Returns(true); _fileSystemService.ReadAllBytesAsync(Arg.Any <string>()) .Returns(_ => { var tcs = new TaskCompletionSource <byte[]>(); tcs.SetResult(_pictureData); return(tcs.Task); }); _imageService = Substitute.For <IImageService>(); _imageService.GetThumbnailAsync(Arg.Any <string>()) .Returns(_ => { var tcs = new TaskCompletionSource <byte[]>(); tcs.SetResult(_miniatureData); return(tcs.Task); }); }
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); }
private void SetUp() { _snapshots = new List <LocationSnapshot> { new LocationSnapshot { Id = 1, PictureFileName = "Barcelona_1.jpg" }, new LocationSnapshot { Id = 2, PictureFileName = "Barcelona_2.jpg" }, new LocationSnapshot { Id = 3, PictureFileName = "Barcelona_3.jpg" } }; _miniatures = new List <SnapshotMiniature> { new SnapshotMiniature { Snapshot = _snapshots[0] }, new SnapshotMiniature { Snapshot = _snapshots[1] }, new SnapshotMiniature { Snapshot = _snapshots[2] } }; _thumbnail = new object(); _snapshotDataService = Substitute.For <ILocationSnapshotDataService>(); _snapshotDataService.GetSnapshotsByLocationIdAsync(Arg.Any <int>()) .Returns(_ => { var tcs = new TaskCompletionSource <IEnumerable <LocationSnapshot> >(); tcs.SetResult(_snapshots); return(tcs.Task); }); _snapshotDataService.GetSnapshotsByIdsAsync(Arg.Any <IEnumerable <int> >()) .Returns(_ => { var tcs = new TaskCompletionSource <IEnumerable <LocationSnapshot> >(); tcs.SetResult(_snapshots); return(tcs.Task); }); _pictureService = Substitute.For <IPictureService>(); _pictureService.GetSnapshotMiniaturesAsync(Arg.Any <IEnumerable <LocationSnapshot> >()) .Returns(_ => { var tcs = new TaskCompletionSource <IEnumerable <SnapshotMiniature> >(); tcs.SetResult(_miniatures); return(tcs.Task); }); _bitmapConverter = Substitute.For <IBitmapConverter>(); _bitmapConverter.GetBitmapAsync(Arg.Any <byte[]>()) .Returns(_ => { var tcs = new TaskCompletionSource <object>(); tcs.SetResult(_thumbnail); return(tcs.Task); }); _dialogService = Substitute.For <IDialogService>(); _dialogService.ShowConfirmationAsync(Arg.Any <string>()) .Returns(_ => { var tcs = new TaskCompletionSource <ConfirmationAnswer>(); tcs.SetResult(ConfirmationAnswer.OK); return(tcs.Task); }); _navigationService = Substitute.For <INavigationService>(); _platformSpecificActions = Substitute.For <IPlatformSpecificActions>(); }