Exemplo n.º 1
0
        private void sendPostCompleted(object sender, UploadStringCompletedEventArgs e)
        {
            if ((e.Error != null) && (e.Error.GetType().Name == "WebException"))
            {
                WebException    we       = (WebException)e.Error;
                HttpWebResponse response = (System.Net.HttpWebResponse)we.Response;

                switch (response.StatusCode)
                {
                case HttpStatusCode.NotFound:     // 404
                    System.Diagnostics.Debug.WriteLine("Not found!");
                    break;

                case HttpStatusCode.Unauthorized:     // 401
                    System.Diagnostics.Debug.WriteLine("Not authorized!");
                    break;

                default:
                    break;
                }
            }
            else
            {
                LoggedUser user = LoggedUser.Instance;
                user.SetLoggedUser(JsonConvert.DeserializeObject <UserData>(e.Result));
                MainUtil.SetKeyValue <string>("AccessToken", string.Empty);
                MainUtil.SetKeyValue <string>("AccessTokenSecret", string.Empty);
                NavigationService.Navigate(new Uri("/LoggedMainPages/LoggedMainPage.xaml", UriKind.Relative));
            }
        }
Exemplo n.º 2
0
        void AccessTokenQuery_QueryResponse(object sender, WebQueryResponseEventArgs e)
        {
            try
            {
                StreamReader reader      = new StreamReader(e.Response);
                string       strResponse = reader.ReadToEnd();
                var          parameters  = MainUtil.GetQueryParameters(strResponse);
                accessToken       = parameters["oauth_token"];
                accessTokenSecret = parameters["oauth_token_secret"];
                userID            = parameters["user_id"];
                userScreenName    = parameters["screen_name"];

                MainUtil.SetKeyValue <string>("AccessToken", accessToken);
                MainUtil.SetKeyValue <string>("AccessTokenSecret", accessTokenSecret);
                MainUtil.SetKeyValue <string>("ScreenName", userScreenName);
                MainUtil.SetKeyValue <string>("UserID", userID);

                userLoggedIn();

                Dispatcher.BeginInvoke(() =>
                {
                    AutenticaChangeColor();
                    //MessageBox.Show("Você está autenticado! Agora escolha a cor e acompanhe no twitter a conta @iot4dx", "MICROSOFT @ TDC 2014", MessageBoxButton.OK);
                });
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(ex.Message);
                });
            }
        }
        private void AccessTokenRequestCallback(RestRequest request, RestResponse response, object obj)
        {
            try
            {
                string respContent = response.Content;
                var    parameters  = MainUtil.GetQueryParameters(respContent);
                accessToken       = parameters["oauth_token"];
                accessTokenSecret = parameters["oauth_token_secret"];

                MainUtil.SetKeyValue <string>("AccessToken", accessToken);
                MainUtil.SetKeyValue <string>("AccessTokenSecret", accessTokenSecret);

                Dispatcher.BeginInvoke(() =>
                {
                    // finding current user's profile
                    getCurrentUserProfile();
                });
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(ex.Message);
                });
            }
        }
 private async void Yes_Click(object sender, RoutedEventArgs e)
 {
     LoggedUser.Instance.userReg.LinkedInId = "";
     await new WebBrowser().ClearCookiesAsync();
     MainUtil.SetKeyValue <string>("AccessToken", string.Empty);
     MainUtil.SetKeyValue <string>("AccessTokenSecret", string.Empty);
     NavigationService.Navigate(new Uri("/LoggedMainPages/Register2.xaml", UriKind.Relative));
 }
Exemplo n.º 5
0
 protected async override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
 {
     e.Cancel = true;
     LoggedUser.Instance.userReg.FacebookId = "";
     FacebookSessionCacheProvider.Current.DeleteSessionData();
     await new WebBrowser().ClearCookiesAsync();
     App.isAuthenticated = false;
     LoggedUser.Instance.userReg.LinkedInId = "";
     MainUtil.SetKeyValue <string>("AccessToken", string.Empty);
     MainUtil.SetKeyValue <string>("AccessTokenSecret", string.Empty);
     NavigationService.Navigate(new Uri("/LoggedMainPages/Register.xaml", UriKind.Relative));
 }
 private void updateUI()
 {
     Deployment.Current.Dispatcher.BeginInvoke(() =>
     {
         if (currentPerson != null)
         {
             MainUtil.SetKeyValue <string>("AccessToken", string.Empty);
             MainUtil.SetKeyValue <string>("AccessTokenSecret", string.Empty);
             NavigationService.Navigate(new Uri("/LoggedMainPages/Register2.xaml", UriKind.Relative));
         }
     });
 }
        private void LinkedInLoginPage_Loaded(object sender, EventArgs e)
        {
            MainUtil.SetKeyValue <string>("AccessToken", string.Empty);
            MainUtil.SetKeyValue <string>("AccessTokenSecret", string.Empty);
            accessToken       = MainUtil.GetKeyValue <string>("AccessToken");
            accessTokenSecret = MainUtil.GetKeyValue <string>("AccessTokenSecret");

            if (string.IsNullOrEmpty(accessToken) || string.IsNullOrEmpty(accessTokenSecret))
            {
                var requestTokenQuery = OAuthUtil.GetRequestTokenQuery();
                requestTokenQuery.RequestAsync(AppSettings.RequestTokenUri, null);
                requestTokenQuery.QueryResponse += new EventHandler <WebQueryResponseEventArgs>(requestTokenQuery_QueryResponse);
            }
            else
            {
                Dispatcher.BeginInvoke(() =>
                {
                    // finding current user's profile if already signed in
                    getCurrentUserProfile();
                });
            }
        }