private void ExtractFollowersAndFriendsFromUser(string userId, UserIdList contactList) { var opt = new RepositoryOptions(); var friendsReps = new FriendsIdList(); var followersReps = new FollowerIdList(); var mainUser = new TwitterAPPUser(); mainUser.id_str = userId; var newUserToSave = new TwitterAPPUser(); var userDB = new UserRepository(); var followerDB = new UserRelationshipRepository(); // Get the friend list of this user opt.twitterUser.id_str = mainUser.id_str; var actualUserFriendIdList = friendsReps.GetFriends(opt); // Select a list of these friends that are in the friends/followers list of the user var idListToProcess = new UserIdList(); idListToProcess.ids.AddRange(from actualUserId in actualUserFriendIdList.ids where contactList.ids.Contains(actualUserId) select actualUserId); // List all this users ids foreach (decimal actualUserId in idListToProcess.ids) { // Save the relationship of this user newUserToSave = new TwitterAPPUser(); newUserToSave.id_str = actualUserId.ToString(); followerDB.SaveUserFollower(newUserToSave, mainUser); } // Get the follower list of this user idListToProcess.ids.Clear(); opt.twitterUser.id_str = mainUser.id_str; var actualUserFollowerIdList = followersReps.GetFollowers(opt); // Select a list of these followers that are in the friends/followers list of the user idListToProcess.ids.AddRange(from actualUserId in actualUserFollowerIdList.ids where contactList.ids.Contains(actualUserId) select actualUserId); // List all this users ids foreach (decimal actualUserId in idListToProcess.ids) { // Save the relationship of this user newUserToSave = new TwitterAPPUser(); newUserToSave.id_str = actualUserId.ToString(); followerDB.SaveUserFollower(mainUser, newUserToSave); } // After all, indicate the user was processed userDB.SetUserAsProcessed(mainUser); }
public void GenerateNetWorkStatistics(NetWorkStatisticsProperties searchProp) { // Cleaning database var userDB = new UserRepository(); var followerDB = new UserRelationshipRepository(); // Main list var processedUserList = new TwitterUserList(); // Used in the interaction // Arrays of friends and followers var friendsReps = new FriendsIdList(); var followersReps = new FollowerIdList(); var userLookUp = new UserLookUp(); var relationshipReps = new GetRelationshipStatus(); var followersList = new List<TwitterAPPUser>(); var followersIdList = new UserIdList(); var friendsList = new List<TwitterAPPUser>(); var friendsIdList = new UserIdList(); var opt = new RepositoryOptions(); var newFollowersUser = new TwitterAPPUser(); var newFriendUser = new TwitterAPPUser(); var newUserToSave = new TwitterAPPUser(); // Lists of FR and FF from each user var actualUserFriendIdList = new UserIdList(); var actualUserFollowerIdList = new UserIdList(); var idListToProcess = new UserIdList(); var userListToProcess = new List<TwitterAPPUser>(); var relationshipStatus = new RelationshipStatus_FinalResult(); // Determine the kind of process if (searchProp.generateNewStatistic == true) { userDB.EraseAllData(); followerDB.EraseAllData(); // Setting the user for the first time opt.twitterUser.screen_name = searchProp.twitterName; // Loading me as the first user var twitterUserRep = new LoadUser(); var mainUser = twitterUserRep.GetUser(opt); // Save the user userDB.SaveNewUser(mainUser); userDB.SetUserAsProcessed(mainUser); // To impeding the first user to be processed again // Generation of FR (friends) and FF (followers) list opt.twitterUser.id_str = mainUser.id_str; // Getting the friends and followers list followersIdList = followersReps.GetFollowers(opt); friendsIdList = friendsReps.GetFriends(opt); opt.userList = followersIdList; followersList = userLookUp.GetUserCompleteList(opt); opt.userList = friendsIdList; friendsList = userLookUp.GetUserCompleteList(opt); // Reading all followers list foreach (TwitterAPPUser user in followersList) { // Save the current user userDB.SaveNewUser(user); // Save the relationship followerDB.SaveUserFollower(mainUser, user); } // Reading all friends list foreach (TwitterAPPUser user in friendsList) { // Save the current user userDB.SaveNewUser(user); // Save the relationship followerDB.SaveUserFollower(user, mainUser); } // Combinning the 2 list userListToProcess.AddRange(friendsList); userListToProcess.AddRange(followersList); } else { // Load the list of the users userListToProcess = userDB.LoadUnprocessedUsers(); } // Reading all this list, to get each contacts foreach (TwitterAPPUser userSource in userListToProcess) { foreach (TwitterAPPUser userTarget in userListToProcess) { opt.twitterUser = userSource; opt.twitterUser_Target = userTarget; relationshipStatus = relationshipReps.Get(opt); // Saving the user relationship, by the result response if (relationshipStatus.relationship.target.following == true) followerDB.SaveUserFollower(userSource, userTarget); if (relationshipStatus.relationship.target.followed_by == true) followerDB.SaveUserFollower(userTarget, userSource); } // After all, indicate the user was processed userDB.SetUserAsProcessed(userSource); } }
public void GenerateNetWorkStatistics(string twitterName, string deepnessCount) { // Cleaning database var userDB = new UserRepository(); var followerDB = new UserRelationshipRepository(); userDB.EraseAllData(); followerDB.EraseAllData(); // Main list var userListToProcess = new TwitterUserList(); var processedUserList = new TwitterUserList(); // Used in the interaction // Arrays of friends and followers var friendsReps = new FriendsIdList(); var followersReps = new FollowerIdList(); var userLookUp = new UserLookUp(); var followersList = new List<TwitterAPPUser>(); var followersIdList = new UserIdList(); var friendsList = new List<TwitterAPPUser>(); var friendsIdList = new UserIdList(); var opt = new RepositoryOptions(); var newFollowersUser = new TwitterAPPUser(); var newFriendUser = new TwitterAPPUser(); // Setting the user for the first time opt.twitterUser.screen_name = twitterName; // Loading me as the first user var twitterUserRep = new LoadUser(); var firstUser = twitterUserRep.GetUser(opt); // Setting the first array userListToProcess.users.Add(firstUser); opt.twitterUser.screen_name = ""; // Main loop for (int processorCount = 0; processorCount < Int16.Parse(deepnessCount); processorCount++) { foreach (TwitterAPPUser user in userListToProcess.users) { // Setting the user for the first time opt.twitterUser.id_str = user.id_str; // Verify if the user is the same of the first if (user.id_str == firstUser.id_str && userListToProcess.users.Count > 1) continue; // Getting the friends and followers list followersIdList = followersReps.GetFollowers(opt); opt.userList.ids = followersIdList.ids; //followersList = userLookUp.GetUserCompleteList(opt); friendsIdList = friendsReps.GetFriends(opt); opt.userList.ids = friendsIdList.ids; //friendsList = userLookUp.GetUserCompleteList(opt); foreach (decimal followerUserId in followersIdList.ids ) { newFollowersUser = new TwitterAPPUser(); newFollowersUser.id_str = followerUserId.ToString(); newFollowersUser.screen_name = ""; // Saving the the twitters users //if (userDB.LoadUser(newFollowersUser.id_str) == null) userDB.SaveNewUser(newFollowersUser); followerDB.SaveUserFollower(user, newFollowersUser); // Appending these users to the result processedUserList.users.Add(newFollowersUser); } foreach (decimal friendUserId in friendsIdList.ids) { newFriendUser = new TwitterAPPUser(); newFriendUser.id_str = friendUserId.ToString(); newFriendUser.screen_name = ""; // Saving the the twitters users //if (userDB.LoadUser(newFriendUser.id_str) == null) userDB.SaveNewUser(newFriendUser); followerDB.SaveUserFollower(newFriendUser, user); // Appending these users to the result processedUserList.users.Add(newFriendUser); } processedUserList.users.AddRange(friendsList); } // Setting the result to the main list userListToProcess.users.Clear(); userListToProcess.users.AddRange(processedUserList.users); processedUserList.users.Clear(); } }