Пример #1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            VisualStateManager.GoToState(this, "InitializingPhoto", false);

            viewModel = (MainPageViewModel)DataContext;

            RegisterOrientationEventHandlers();

            var token = App.Settings.Values["Token"].ToString();

            HttpClient hc = new HttpClient();

            hc.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
            var result = await hc.GetAsync("https://graph.microsoft.com/v1.0/me");

            if (result.IsSuccessStatusCode)
            {
                string res = await result.Content.ReadAsStringAsync();

                OfficeUser user = JsonConvert.DeserializeObject <OfficeUser>(res);

                ((MainPageViewModel)DataContext).UserName = user.displayName;

                viewModel.OxfordStatus = "Checking if we know you...";

                bool userRegistered = await checkUserRegistrationAsync();

                if (!userRegistered)
                {
                    viewModel.OxfordStatus = "Looks like we haven't seen you yet. \nNo problem, take some pictures of your face. Five should be enough.";
                }
                else
                {
                    viewModel.OxfordStatus = "Welcome back!";

                    var ud = FaceApiService.DeserializeUserData(currentPerson.userData);
                    ud.AccessToken         = token;
                    currentPerson.userData = FaceApiService.SerializeUserData(ud);

                    await FaceApiService.UpdatePersonAsync(personGroupId, currentPerson);
                }
            }

            await InitializeCameraAsync();

            await CreateFaceDetectionEffectAsync();
        }