public void addTwitterStats(TwitterStats TwtStats) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { session.Save(TwtStats); transaction.Commit(); } } }
public int updateTwitterStats(TwitterStats TwtStats) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { int i = session.CreateQuery("Update from TwitterStats where TwitterId = :twtuserid and UserId = :userid") .SetParameter("twtuserid", TwtStats.TwitterId) .SetParameter("userid", TwtStats.UserId) .ExecuteUpdate(); transaction.Commit(); return i; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return 0; } } } }
/// <summary> /// /// </summary> private void getTwitterUserProfile() { var requestToken = (String)Request.QueryString["oauth_token"]; var requestSecret = (String)Session["requestSecret"]; var requestVerifier = (String)Request.QueryString["oauth_verifier"]; OAuth.AccessToken = requestToken; OAuth.AccessTokenSecret = requestVerifier; OAuth.AccessTokenGet(requestToken, requestVerifier); JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, OAuth.TwitterScreenName); User user = (User)Session["LoggedUser"]; SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository(); SocialProfile socioprofile = new SocialProfile(); #region for managing referrals ManageReferrals(OAuth); #endregion foreach (var item in profile) { try { twitterAccount.FollowingCount = Convert.ToInt32(item["friends_count"].ToString()); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twitterAccount.FollowersCount = Convert.ToInt32(item["followers_count"].ToString()); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } twitterAccount.Id = Guid.NewGuid(); twitterAccount.IsActive = true; twitterAccount.OAuthSecret = OAuth.AccessTokenSecret; twitterAccount.OAuthToken = OAuth.AccessToken; try { twitterAccount.ProfileImageUrl = item["profile_image_url"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twitterAccount.ProfileUrl = string.Empty; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { twitterAccount.TwitterUserId = item["id_str"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception er) { try { twitterAccount.TwitterUserId = item["id"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception err) { Console.WriteLine(err.StackTrace); } Console.WriteLine(er.StackTrace); } try { twitterAccount.TwitterScreenName = item["screen_name"].ToString().TrimStart('"').TrimEnd('"'); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } twitterAccount.UserId = user.Id; socioprofile.Id = Guid.NewGuid(); socioprofile.ProfileDate = DateTime.Now; socioprofile.ProfileId = twitterAccount.TwitterUserId; socioprofile.ProfileType = "twitter"; socioprofile.UserId = user.Id; if (HttpContext.Current.Session["login"] != null) { if (HttpContext.Current.Session["login"].ToString().Equals("twitter")) { User usr = new User(); UserRepository userrepo = new UserRepository(); Registration regObject = new Registration(); usr.AccountType = "free"; usr.CreateDate = DateTime.Now; usr.ExpiryDate = DateTime.Now.AddMonths(1); usr.Id = Guid.NewGuid(); usr.UserName = twitterAccount.TwitterName; usr.Password = regObject.MD5Hash(twitterAccount.TwitterName); usr.EmailId = ""; usr.UserStatus = 1; if (!userrepo.IsUserExist(usr.EmailId)) { UserRepository.Add(usr); } } } TwitterStatsRepository objTwtstats = new TwitterStatsRepository(); TwitterStats objStats = new TwitterStats(); Random rNum = new Random(); objStats.Id = Guid.NewGuid(); objStats.TwitterId = twitterAccount.TwitterUserId; objStats.UserId = user.Id; objStats.FollowingCount = twitterAccount.FollowingCount; objStats.FollowerCount = twitterAccount.FollowersCount; objStats.Age1820 = rNum.Next(twitterAccount.FollowersCount); objStats.Age2124 = rNum.Next(twitterAccount.FollowersCount); objStats.Age2534 = rNum.Next(twitterAccount.FollowersCount); objStats.Age3544 = rNum.Next(twitterAccount.FollowersCount); objStats.Age4554 = rNum.Next(twitterAccount.FollowersCount); objStats.Age5564 = rNum.Next(twitterAccount.FollowersCount); objStats.Age65 = rNum.Next(twitterAccount.FollowersCount); objStats.EntryDate = DateTime.Now; if (!objTwtstats.checkTwitterStatsExists(twitterAccount.TwitterUserId, user.Id)) objTwtstats.addTwitterStats(objStats); if (!twtrepo.checkTwitterUserExists(twitterAccount.TwitterUserId, user.Id)) { twtrepo.addTwitterkUser(twitterAccount); if (!socioprofilerepo.checkUserProfileExist(socioprofile)) { socioprofilerepo.addNewProfileForUser(socioprofile); } else { socioprofilerepo.updateSocialProfile(socioprofile); } } else { twtrepo.updateTwitterUser(twitterAccount); TwitterMessageRepository twtmsgreponew = new TwitterMessageRepository(); twtmsgreponew.updateScreenName(twitterAccount.TwitterUserId, twitterAccount.TwitterScreenName); if (!socioprofilerepo.checkUserProfileExist(socioprofile)) { socioprofilerepo.addNewProfileForUser(socioprofile); } else { socioprofilerepo.updateSocialProfile(socioprofile); } } if (Session["UserAndGroupsForTwitter"] != null) { if (Session["UserAndGroupsForTwitter"].ToString() == "twitter") { try { if (Session["GroupName"] != null) { Groups group = (Groups)Session["GroupName"]; GroupProfile groupprofile = new GroupProfile(); GroupProfileRepository groupprofilerepo = new GroupProfileRepository(); groupprofile.Id = Guid.NewGuid(); groupprofile.ProfileId = socioprofile.ProfileId; groupprofile.ProfileType = "twitter"; groupprofile.GroupOwnerId = user.Id; groupprofile.EntryDate = DateTime.Now; groupprofile.GroupId = group.Id; if (!groupprofilerepo.checkGroupProfileExists(user.Id, group.Id, groupprofile.ProfileId)) { groupprofilerepo.AddGroupProfile(groupprofile); } } } catch (Exception e) { Console.WriteLine(e.StackTrace); } } } } }
public void getTwitterStats(TwitterAccount twitterAccount) { TwitterStatsRepository objTwtstats = new TwitterStatsRepository(); TwitterMessageRepository objTweetMsgRepo = new TwitterMessageRepository(); TwitterStats objStats = new TwitterStats(); Random rNum = new Random(); objStats.Id = Guid.NewGuid(); objStats.TwitterId = twitterAccount.TwitterUserId; objStats.UserId = twitterAccount.UserId; objStats.FollowingCount = twitterAccount.FollowingCount; objStats.FollowerCount = twitterAccount.FollowersCount; objStats.Age1820 = rNum.Next(twitterAccount.FollowersCount); objStats.Age2124 = rNum.Next(twitterAccount.FollowersCount); objStats.Age2534 = rNum.Next(twitterAccount.FollowersCount); objStats.Age3544 = rNum.Next(twitterAccount.FollowersCount); objStats.Age4554 = rNum.Next(twitterAccount.FollowersCount); objStats.Age5564 = rNum.Next(twitterAccount.FollowersCount); objStats.Age65 = rNum.Next(twitterAccount.FollowersCount); int replies = objTweetMsgRepo.getRepliesCount(twitterAccount.UserId, twitterAccount.TwitterUserId); int retweets = objTweetMsgRepo.getRetweetCount(twitterAccount.UserId, twitterAccount.TwitterUserId); if (twitterAccount.FollowersCount != 0) objStats.Engagement = (replies + retweets) / twitterAccount.FollowersCount; else objStats.Engagement = 0; // objStats.Influence= // objStats.Engagement= objStats.EntryDate = DateTime.Now; if (!objTwtstats.checkTwitterStatsExists(twitterAccount.TwitterUserId, twitterAccount.UserId)) objTwtstats.addTwitterStats(objStats); }