private async void TabGesture_Tapped(object sender, EventArgs e) { if (LoginViewModel.Instance.IsLoggedIn) { try { var profile = await MvpService.GetProfile(LoginViewModel.StoredToken); MvpHelper.SetDataToProfileViewModel(profile); if (string.IsNullOrEmpty(MyProfileViewModel.Instance.StoreImageBase64Str)) { MyProfileViewModel.Instance.StoreImageBase64Str = await MvpService.GetPhoto(LoginViewModel.StoredToken); } } catch (Exception ex) { MyProfileViewModel.Instance.StoreImageBase64Str = CommonConstants.DefaultPhoto; MyProfileViewModel.Instance.ErrorMessage = ex.Message; } await Navigation.PushModalAsync(new MyProfile()); } else { await Navigation.PushModalAsync(new LiveIdLogin()); } }
private async void makeAccessTokenRequest(string requestUrl) { HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest; string responseTxt = String.Empty; using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse) { var reader = new StreamReader(response.GetResponseStream()); responseTxt = reader.ReadToEnd(); var tokenData = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseTxt); if (tokenData.ContainsKey("access_token")) { App.Current.Properties.Add("access_token", tokenData["access_token"]); LoginViewModel.StoredToken = tokenData["access_token"]; // refresh token App.Current.Properties.Add("refresh_token", tokenData["refresh_token"]); // testing refresh token // var ret = await GetNewAccessToken(); var profile = await MvpService.GetProfile(LoginViewModel.StoredToken); MvpHelper.SetDataToProfileViewModel(profile); var photobase64Str = await MvpService.GetPhoto(LoginViewModel.StoredToken); LoginViewModel.StoreImageBase64Str = photobase64Str; var myprofileView = new MyProfile(); myprofileView.SetPhoto(photobase64Str); await Navigation.PushModalAsync(myprofileView); Application.Current.Properties[CommonConstants.TokenKey] = string.Format("{0},{1}", LoginViewModel.StoredToken, DateTime.Now); } } }