Ejemplo n.º 1
0
        //****** OPERATIONS
        public override UserProfile GetProfile()
        {
            //If token already has profile for this provider, we can return it to avoid a call
            Token token = ConnectionToken;

            if (token.Profile.IsSet)
            {
                logger.Debug("Profile successfully returned from session");
                return(token.Profile);
            }

            //Fetch Profile
            OAuthStrategyBase strategy = AuthenticationStrategy;
            string            response = "";

            try
            {
                logger.Debug("Executing profile feed");
                Stream responseStream = strategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream();
                response = new StreamReader(responseStream).ReadToEnd();
            }
            catch
            {
                throw;
            }

            try
            {
                JObject profileJson = JObject.Parse(response);
                token.Profile.ID                = profileJson.Get("id");
                token.Profile.FirstName         = profileJson.Get("first_name");
                token.Profile.LastName          = profileJson.Get("last_name");
                token.Profile.Country           = profileJson.Get("Location");
                token.Profile.ProfilePictureURL = profileJson.Get("ThumbnailImageLink");
                token.Profile.Email             = profileJson.Get("emails.account");
                token.Profile.GenderType        = Utility.ParseGender(profileJson.Get("gender"));
                if (!string.IsNullOrEmpty(ProfileEndpoint))
                {
                    token.Profile.ProfilePictureURL = strategy.ExecuteFeed(ProfilePictureEndpoint, this, token, TRANSPORT_METHOD.GET).ResponseUri.AbsoluteUri.Replace("\"", "");
                }
                token.Profile.IsSet = true;
                logger.Info("Profile successfully received");
                return(token.Profile);
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.ProfileParsingError(response), ex);
                throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex);
            }
        }
Ejemplo n.º 2
0
        //****** OPERATIONS
        public override UserProfile GetProfile()
        {
            Token             token    = ConnectionToken;
            OAuthStrategyBase strategy = AuthenticationStrategy;
            string            response = "";


            //If token already has profile for this provider, we can return it to avoid a call
            if (token.Profile.IsSet)
            {
                logger.Debug("Profile successfully returned from session");
                return(token.Profile);
            }

            try
            {
                logger.Debug("Executing Profile feed");
                Stream responseStream = strategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream();
                response = new StreamReader(responseStream).ReadToEnd();
            }
            catch
            {
                throw;
            }

            try
            {
                JObject jsonObject = JObject.Parse(response);
                token.Profile.ID          = jsonObject.Get("user_id");
                token.Profile.FirstName   = jsonObject.Get("name");
                token.Profile.DisplayName = token.Profile.FullName;
                token.Profile.Email       = HttpUtility.UrlDecode(jsonObject.Get("email"));
                token.Profile.IsSet       = true;
                logger.Info("Profile successfully received");
                //Session token updated with profile
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.ProfileParsingError(response), ex);
                throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex);
            }

            return(token.Profile);
        }
Ejemplo n.º 3
0
        public override List <Contact> GetContacts()
        {
            Token             token          = ConnectionToken;
            OAuthStrategyBase strategy       = this.AuthenticationStrategy;
            Stream            responseStream = null;
            string            response       = "";

            try
            {
                logger.Debug("Executing contacts feed");
                responseStream = strategy.ExecuteFeed(ContactsEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream();
                response       = new StreamReader(responseStream).ReadToEnd();
            }
            catch
            {
                throw;
            }

            try
            {
                JObject jsonObject = JObject.Parse(response);
                var     friends    = from f in jsonObject["data"].Children()
                                     select new Contact
                {
                    Name              = (string)f["name"],
                    ID                = (string)f["id"],
                    ProfileURL        = "http://www.facebook.com/profile.php?id=" + (string)f["id"],
                    ProfilePictureURL = "https://graph.facebook.com/" + (string)f["id"] + "/picture"
                };
                logger.Info("Contacts successfully received");
                return(friends.ToList <Contact>());
            }

            catch (Exception ex)
            {
                logger.Error(ErrorMessages.ContactsParsingError(response), ex);
                throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex);
            }
        }
Ejemplo n.º 4
0
        //****** OPERATIONS
        public override UserProfile GetProfile()
        {
            Token             token    = ConnectionToken;
            OAuthStrategyBase strategy = AuthenticationStrategy;
            string            response = "";


            //If token already has profile for this provider, we can return it to avoid a call
            if (token.Profile.IsSet)
            {
                logger.Debug("Profile successfully returned from session");
                return(token.Profile);
            }

            try
            {
                logger.Debug("Executing Profile feed");
                Stream responseStream = strategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream();
                response = new StreamReader(responseStream).ReadToEnd();
            }
            catch
            {
                throw;
            }

            try
            {
                JObject jsonObject = JObject.Parse(response);
                token.Profile.ID          = jsonObject.Get("id");
                token.Profile.FirstName   = jsonObject.Get("first_name");
                token.Profile.LastName    = jsonObject.Get("last_name");
                token.Profile.Username    = jsonObject.Get("username");
                token.Profile.DisplayName = token.Profile.FullName;
                string[] locale = jsonObject.Get("locale").Split(new char[] { '_' });
                if (locale.Length > 0)
                {
                    token.Profile.Language = locale[0];
                    token.Profile.Country  = locale[1];
                }
                token.Profile.ProfileURL = jsonObject.Get("link");
                token.Profile.Email      = HttpUtility.UrlDecode(jsonObject.Get("email"));
                if (!string.IsNullOrEmpty(jsonObject.Get("birthday")))
                {
                    string[] dt = jsonObject.Get("birthday").Split(new char[] { '/' });
                    token.Profile.DateOfBirth = dt[1] + "/" + dt[0] + "/" + dt[2];
                }
                token.Profile.GenderType = Utility.ParseGender(jsonObject.Get("gender"));
                //get profile picture
                if (!string.IsNullOrEmpty(ProfilePictureEndpoint))
                {
                    token.Profile.ProfilePictureURL = strategy.ExecuteFeed(ProfilePictureEndpoint, this, token, TRANSPORT_METHOD.GET).ResponseUri.AbsoluteUri.Replace("\"", "");
                }
                token.Profile.IsSet = true;
                logger.Info("Profile successfully received");
                //Session token updated with profile
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.ProfileParsingError(response), ex);
                throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex);
            }

            return(token.Profile);
        }
Ejemplo n.º 5
0
        //****** OPERATIONS
        public override UserProfile GetProfile()
        {
            Token             token    = ConnectionToken;
            OAuthStrategyBase strategy = AuthenticationStrategy;
            string            response = "";


            //If token already has profile for this provider, we can return it to avoid a call
            if (token.Profile.IsSet)
            {
                logger.Debug("Profile successfully returned from session");
                return(token.Profile);
            }

            try
            {
                logger.Debug("Executing Profile feed");
                Stream responseStream = strategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream();
                response = new StreamReader(responseStream).ReadToEnd();
            }
            catch
            {
                throw;
            }

            try
            {
                XDocument profileXml = XDocument.Parse(response);
                XElement  person     = profileXml.Element("person");
                token.Profile.ID = person.Element("id") != null?person.Element("id").Value : "";

                token.Profile.ProfileURL = "http://www.linkedin.com/profile/view?id=" + person.Element("id").Value;
                token.Profile.FirstName  = person.Element("first-name") != null?person.Element("first-name").Value : "";

                token.Profile.LastName = person.Element("first-name") != null?person.Element("last-name").Value : "";

                token.Profile.ProfilePictureURL = person.Element("picture-url") != null?person.Element("picture-url").Value : "";

                token.Profile.Email = person.Element("email-address") != null?person.Element("email-address").Value : "";

                if (person.Element("date-of-birth") != null)
                {
                    string d = person.Element("date-of-birth").Element("day") == null ? "" : person.Element("date-of-birth").Element("day").Value;
                    string m = person.Element("date-of-birth").Element("month") == null ? "" : person.Element("date-of-birth").Element("month").Value;
                    string y = person.Element("date-of-birth").Element("year") == null ? "" : person.Element("date-of-birth").Element("year").Value;
                    token.Profile.DateOfBirth = string.Join("/", d, m, y);
                }

                if (person.Element("location") != null)
                {
                    person.Element("location").Elements().ToList().ForEach(
                        x => token.Profile.Country += x.Value);
                }

                token.Profile.IsSet = true;
                logger.Info("Profile successfully received");
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.ProfileParsingError(response), ex);
                throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex);
            }
            return(token.Profile);
        }