public ProfileCreated()
 {
     InitializeComponent();
     FaceSdkHelper = new SdkHelper();
     DataContext = this;
     IsCalculating = true;
 }
 public Survival()
 {
     InitializeComponent();
     FaceSdkHelper = new SdkHelper();
     DataContext = this;
 }
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     counter.Stop();
     counter.Tick -= counter_Tick;
     FaceSdkHelper = null;
     GC.Collect();
     base.OnNavigatedFrom(e);
 }
        private async Task startHardWork()
        {
            worker = new BackgroundWorker();
            worker.DoWork += (sender, arg) =>
            {
                FaceSdkHelper.Initialize();
            };
            await worker.BeginWorkerAsync();

            var sdkImg = ImageConverter.SystemToSdk(imageBitmap);
            var result = FaceSdkHelper.Detect(sdkImg);

            if (SdkHelper.foundFace == true && SdkHelper.results.Count == 1)
            {
                var shape = SdkHelper.results.FirstOrDefault();

                var defaultFaceCalculations = Calculus.ReadDefaultFaceCalculations();
                var array = FaceCalculationsHelpers.FromFaceCalculationsToVector(defaultFaceCalculations);

                var calculatedFaceCalculations = Calculus.GetFaceCalculationsFromShape(shape);
                var resultArray = FaceCalculationsHelpers.FromFaceCalculationsToVector(calculatedFaceCalculations);

                var conditions = new Conditions();
                var resultFromCalculus = conditions.GetLevelVerifierFunction(Level).Invoke(array, resultArray);

                if (resultFromCalculus != 0)
                {
                    using (var db = new GrimacizerContext(GrimacizerContext.ConnectionString))
                    {
                        var passedLevels = db.Settings.FirstOrDefault()._16_PassedLevels;
                        db.Settings.FirstOrDefault()._16_PassedLevels = Math.Max(passedLevels, Level);

                        var level = db.Levels.FirstOrDefault(t => t.Level == Level);
                        level.Stars = Math.Max(resultFromCalculus, level.Stars);

                        db.SubmitChanges();
                    }
                    MessageBox.Show("Level passed. You won " + resultFromCalculus + " point" + (resultFromCalculus > 1 ? "s!" : "!"));
                }
                else
                {
                    InGameLifeHelpers.LoseLife();
                    MessageBox.Show("Level failed");
                }
            }
            else
            {
                MessageBox.Show("Camera did not detect your face! Try again!");
            }

            NavigationService.Navigate(new Uri(Pages.GeneralGameplay_Adventure, UriKind.RelativeOrAbsolute));
            FaceSdkHelper = null;
            GC.Collect();
        }
        public TakePhoto()
        {
            InitializeComponent();
            InitScene();
            FaceSdkHelper = new SdkHelper();
            DataContext = this;

            Message = string.Empty;
            IsCalculating = false;
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.Back)
                return;

            SystemTray.IsVisible = true;

            int width, height;
            using (var db = new GrimacizerContext(GrimacizerContext.ConnectionString))
            {
                var settings = db.Settings.FirstOrDefault();
                width = settings.DefaultImagePixelWidth;
                height = settings.DefaultImagePixelHeight;
            }
            ImageSource = LocalImagesHelper.ReadImageFromIsolatedStorage(Constants.DEFAULT_FACE_PHOTO, width, height);

            var worker = new BackgroundWorker();
            worker.DoWork += (sender, arg) =>
            {
                FaceSdkHelper.Initialize();
            };
            await worker.BeginWorkerAsync();

            var sdkImg = ImageConverter.SystemToSdk(ImageSource);
            var result = FaceSdkHelper.Detect(sdkImg);
            ImageSource = ImageConverter.SdkToSystem(result);

            if (SdkHelper.foundFace == true && SdkHelper.results.Count == 1)
            {
                (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true;
                (ApplicationBar.Buttons[1] as ApplicationBarIconButton).IsEnabled = true;
                IsCalculating = false;
            }
            else
            {
                MessageBox.Show("Camera did not detect your face! Try again!");
                NavigationService.GoBack();
            }

            FaceSdkHelper = null;
            GC.Collect();
        }