Inheritance: ViewModelBase
 public ProductRecommendation GetRecommendedUri(FaceViewModel face)
 {
     if (face != null && face.Age != null && face.Gender != null)
     {
         if (face.Age >= 0 && face.Age < 17)
             return XboxOne;
         else if (face.Age < 23 && face.Gender == "female")
             return SurfacePro;
         else if (face.Age < 23 && face.Gender == "male")
             return Office365;
         else if (face.Age < 30)
             return Lumia950;
         else if (face.Age < 40)
             return SurfaceBook;
         else
             return SurfaceStudio;
     }
     return AllTablets;
 }
Ejemplo n.º 2
0
        private async void TakePhoto(string operationType)
        {
            try
            {
                if (operationType == null)
                {
                    throw new ArgumentNullException(nameof(operationType));
                }

                StorageFile photo = null;
                switch (operationType)
                {
                case "capture":
                    photo = await CapturePhoto();

                    break;

                case "library":
                    photo = await PickPhoto();

                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(operationType), "Unknown value: " + (operationType ?? "NULL"));
                }

                if (photo == null)
                {
                    return;
                }

                Photo = await PreparePhoto(photo);

                IsPhotoUnderProcessing = true;
                var faces = await _faceClient.DetectAsync((await photo.OpenAsync(FileAccessMode.Read)).AsStream(), returnFaceAttributes : Enum.GetValues(typeof(FaceAttributeType)).Cast <FaceAttributeType>());

                DetectedFaces          = new ObservableCollection <FaceViewModel>(await Task.WhenAll(faces.Select(f => FaceViewModel.FromFace(f, photo))));
                SelectedFace           = DetectedFaces.FirstOrDefault();
                IsPhotoUnderProcessing = false;
            }
            catch (Exception e)
            {
                var dialog = new ContentDialog
                {
                    Title             = "Unexpected error",
                    PrimaryButtonText = "Ok",
                    Content           = new TextBlock
                    {
                        Text         = e.Message,
                        TextWrapping = Windows.UI.Xaml.TextWrapping.WrapWholeWords
                    }
                };
                await dialog.ShowAsync();
            }
        }