示例#1
0
        /// <summary>
        /// Called when [selected picture header].
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <returns></returns>
        private async Task OnSelectedPictureHeader(object payload)
        {
            try
            {
                IsUserInterfaceEnabled = false;
                var picHeader = payload as PictureHeaderViewModel;
                MessageHub.Publish(MessageNames.StatusAvailable, $"Loading selected {picHeader.Name}, Taken on {picHeader.DateTakenUtc}");
                if (picHeader == null)
                {
                    return;
                }

                // Save the picture before switching it.
                if (CurrentPicture != null)
                {
                    await StoreProvider.AddOrUpdatePictureAsync(CurrentPicture);
                }

                CurrentPicture = await StoreProvider.LoadPictureAsync(picHeader.PictureId);

                MessageHub.Publish(MessageNames.StatusAvailable, "Ready");
            }
            catch (Exception ex)
            {
                // We send a status message to the hub but it should really be an Error message of its own type
                MessageHub.Publish(MessageNames.StatusAvailable, $"Error: {ex.Message}");
            }
            finally
            {
                IsUserInterfaceEnabled = true;
            }
        }
示例#2
0
        /// <summary>
        /// Called when [take picture command].
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <returns></returns>
        public async Task OnTakePictureCommand(object payload)
        {
            try
            {
                IsUserInterfaceEnabled = false;
                MessageHub.Publish(MessageNames.StatusAvailable, $"Taking picture from camera . . .");

                var pictureBytes = await Device.TakePicture();

                var pictureLocation = await Device.ReadLocation();

                var picture = new PictureViewModel
                {
                    ImageBytes = pictureBytes
                };

                picture.Header.DateTakenUtc       = DateTime.UtcNow;
                picture.Header.Location.Latitude  = pictureLocation.Latitude;
                picture.Header.Location.Longitude = pictureLocation.Longitude;
                picture.Header.Name      = $"Taken at {DateTime.UtcNow.ToShortTimeString()}";
                picture.Header.PictureId = Guid.NewGuid();

                await StoreProvider.AddOrUpdatePictureAsync(picture);

                PictureHeaders.Add(picture.Header);
                SelectedPictureHeader = picture.Header;

                MessageHub.Publish(MessageNames.StatusAvailable, "Ready");
            }
            catch (Exception ex)
            {
                // We send a status message to the hub but it should really be an Error message of its own type
                MessageHub.Publish(MessageNames.StatusAvailable, $"Error: {ex.Message}");
            }
            finally
            {
                IsUserInterfaceEnabled = true;
            }
        }