Пример #1
0
        public User CreateFrom(GooglePlusUser googleUser)
        {
            var user = new User();

            Map(googleUser, user);

            return user;
        }
Пример #2
0
 public void Map(GooglePlusUser googleUser, User user)
 {
     if (googleUser.Name != null)
     {
         user.FirstName = googleUser.Name.GivenName;
         user.LastName = googleUser.Name.FamilyName;
         user.GoogleId = googleUser.Id;
     }
 }
Пример #3
0
        public void SaveUser(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException();
            }

            log.Info("Saving user: " + user.GoogleId);

            try
            {
                dataAdapter.SaveUser(user);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                throw;
            }
        }
Пример #4
0
        public void ImportData(string googleId, User user = null)
        {
            try
            {
                //get user data from google
                var googleUser = peopleProvider.GetProfile(googleId);

                if (user == null)
                {
                    user = userMapper.CreateFrom(googleUser);
                }
                else
                {
                    userMapper.Map(googleUser, user);
                }

                dataManager.SaveUser(user);

                LoadActivities(googleId, user);

                if (IsFeedSavingEnabled)
                {
                    ImportFeeds(user.Id);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
            }
        }
Пример #5
0
        private void LoadActivities(string userId, User user)
        {
            log.Debug(string.Format("Activities load from GooglePlus started for user: {0}", userId));

            var activities = activitiesProvider.GetActivities(userId);

            var existingActivities = dataManager.GetActivities(user.Id);

            foreach (var item in activities.Items)
            {
                //if google activity already added continue on next activity
                if (item.GoogleObject == null
                    || existingActivities.Any(a => String.Equals(a.googleId, item.Id)))
                {
                    continue;
                }

                Activity activity;

                switch (item.Verb)
                {
                    case "post":
                        activity = activityMapper.CreatePost(item, item.GoogleObject);
                        break;
                    case "share":
                        activity = activityMapper.CreateShare(item, item.GoogleObject);
                        break;
                    default:
                        continue;
                }

                activity.Author = user;

                dataManager.SaveActivity(activity);

                //look for photos
                if (item.GoogleObject.Attachments != null)
                {
                    foreach (var attachment in item.GoogleObject.Attachments)
                    {
                        if (attachment.ObjectType.Equals("photo"))
                        {
                            var photo = activityMapper.CreatePhoto(item, attachment);
                            photo.Author = user;
                            dataManager.SaveActivity(photo);
                        }
                    }
                }
            }

            log.Debug("Activities load from GooglePlus finished");
        }
Пример #6
0
        public ActionResult Update(User user)
        {
            DataAdapter.SaveUser(user);

            log.Info(String.Format("User '{0}' updated profile", user.FullName));

            return RedirectToAction("Main");
        }