Esempio n. 1
0
        public async void TakePhoto()
        {
            //Checking for camera permissions
            var cameraPermission = await PermissionHandler.CheckForCameraPermission();

            if (!cameraPermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);
            }

            //Checking for storage permissions
            var storagePermission = await PermissionHandler.CheckForCameraPermission();

            if (!storagePermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);
            }

            //Taking photo and storing it in MediaFile variable 'takenPhoto'
            try
            {
                takenPhoto = await TakingPhotoHandler.TakePhoto();
            }

            catch (ManagerException photoNotTakenException)
            {
                ToastUtil.ShowToast(photoNotTakenException.ErrorCode);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks for permissions, takes photo and checks whether target was hit
        /// </summary>
        public async void TakePhoto()
        {
            var cameraPermission = await PermissionHandler.CheckForCameraPermission();

            if (!cameraPermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);
            }

            var storagePermission = await PermissionHandler.CheckForCameraPermission();

            if (!storagePermission)
            {
                await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);
            }
            try
            {
                var takenPhoto = await TakingPhotoHandler.TakePhoto();

                UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);

                var saveImage = User.Id + ".jpg";
                await CloudStorageService.SaveBlockBlob(takenPhoto, saveImage);
            }

            catch (ManagerException photoNotTakenException)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(photoNotTakenException.ErrorCode);

                return;
            }

            try
            {
                var imageName          = User.Id + ".jpg";
                var recognitionMessage = await _restService.Identify(imageName);

                var isTargetDead = await _restService.IsPreyHunted(User.Id, Convert.ToInt32(recognitionMessage));

                if (isTargetDead)
                {
                    DisplayMessage = "It's a direct hit!";
                    OnPropertyChanged("DisplayMessage");

                    var hitResult = await _restService.GetUserById(Convert.ToInt32(recognitionMessage));

                    var historyResult = await _restService.UpdateHistoryModel(User.Id, hitResult.Id);

                    UserDialogs.Instance.HideLoading();

                    //Initiate popup
                    await PopupNavigation.Instance.PushAsync(new ShootPopUp(this));

                    DisplayStatus = "Name: " + hitResult.PersonFirstName;
                    OnPropertyChanged("DisplayStatus");

                    User = await _restService.UpdateUserScore(User.Id);

                    Name = "Your score is: " + User.Score.ToString();
                    OnPropertyChanged("Name");
                }
            }

            catch (ManagerException noFacesFoundException) when(noFacesFoundException.ErrorCode == Constants.NoFacesIdentifiedError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(noFacesFoundException.ErrorCode);
            }

            catch (ManagerException noOneIdentifiedException) when(noOneIdentifiedException.ErrorCode == Constants.NoMatchFoundError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(noOneIdentifiedException.ErrorCode);
            }

            catch (ManagerException targetNotFoundException) when(targetNotFoundException.ErrorCode == Constants.TargetNotFoundError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast(targetNotFoundException.ErrorCode);
            }

            catch (ManagerException userNotFoundException) when(userNotFoundException.ErrorCode == Constants.UserDoesNotExistError)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast("Something went wrong");
            }

            //This catch is just for testing purposes
            catch (ManagerException)
            {
                UserDialogs.Instance.HideLoading();

                ToastUtil.ShowToast("Something went wrong");
            }
        }